How to undo creating a branch and resetting the master index

I created a local repository and made about eight commits.  I have not pushed anything to a remote repository.  Then I realized that I should have put the last three commits into a separate branch so I created a new branch at the sixth commit and set the master to the fifth commit.  There were a couple of changes that had not been committed.  Now it appears that I have only the sixth commit in the branch and the last two commits do not show separately on the branch or the continuation of the master branch, so I'm confused as to what happened to them.  I did not do a stash before creating the branch or resetting the master.

I believe I need to undo the branch/master changes and start over with all commits in the master.  I did create a stash after the fact but am now gun shy about losing the missing commits.

Please Help!

Gary

   

1 answer

Don't worry, they only disappeared because the only branch that was pointing to the 8th commit was master and after you reset it to the 5th commit there was nothing pointing to the last commit any more therefore it doesn't show up anymore in ST but they still exist.

What you need to do is find out what the commit hashes of the missing commits are (you can do this using the command:

git reflog

and then it's up to you but you can either cherry pick them back into a branch individually via command line (I can't see a way to do this in ST) or easier maybe is to just create a new branch/tag where that last commit was. 

In ST it looks like you can create a new tag and specify a commit hash, so if you use the hash of the 8th commit it should create a new tag at that spot and then at least you can see them again and do whatever you want with them after that .

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

563 views 1 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you