Question

Using the MSYSGIT history browser, I checked-out a particular commit. This was a mistake - I was trying to view the files and thought I had to check them out to see them.

Since then, I have been unable to push any more commits to my remote repo (on GITHub). Which I somewhat understand, though not entirely. [I admit to not fully understand how checkout works, please be gentle on a noob.]

How do I undo that checkout and get things back to the state they were in before?

If I right click on the 'checked out' commit, I get the option to 'remove this branch'. Will that delete the files of that commit [bad] or just undo the check out? Am I barking up the wrong tree?

Was it helpful?

Solution

My understanding is that you accidentally checked out an earlier commit, and then made fresh commits on top of that which you'd like to keep. First, ensure you have a pointer to your current work:

git checkout -b newbranch

Then, checkout where you were before:

git checkout master

Hopefully this will put you back on your mainline branch and you can push to GitHub as normal. If you then want to pull in the changes you made, you can then merge and (once you're happy) delete the temporary branch:

git merge newbranch
git branch -d newbranch

OTHER TIPS

A branch is basically a pointer, in C++ terms.

You may want to try moving your branch to point to a different commit. Use git reset for that.

git checkout mybranch
git reset mypreviouscommit

This doesn't delete the commit, but it does make mybranch "point to" mypreviouscommit. So, whatever was there at mypreviouscommit will be there at master.

If you don't mind loosing all the changes you've made since the last pull to GitHUB, you can simply delete your directory and

git clone ...

on a fresh, new one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top