1

I tried to get a former copy of my code by using the git checkout command. Before using this though, I committed the latest version of the code using git commit.

After using git checkout to a previous version, I made changes to the code. Git now informs me that because I've made changes I can no longer revert to that most recent version that I had committed.

I don't care about the changes I made to this code I checked out, I just want to get back to the most recent version of the code. How do I do this?

Using the command git log no longer shows that most recent version before the checkout to a previous version.

3
  • You said "After using git checkout to a previous version". How did you use git checkout to get to a previous version?
    – remi
    Commented Sep 20, 2010 at 20:14
  • Please show which command(s) you used to get to the state you're in now. It's probably easy to get back to where you were, but we'll need to know what you did. Commented Sep 20, 2010 at 20:16
  • Sounds more like you did a checkout of another branch, then you could just revert those changes or commit them and then checkout the branch you want Commented Sep 20, 2010 at 20:18

2 Answers 2

2

You are most certainly in a detached head mode.
That happens when you checkout a commit that is not at the tip of one of your branches (like a tag, git checkout V1.0).

dd http://marklodato.github.com/visual-git-guide/checkout-b-detached.svg

You can discard your temporary commits and merges by switching back to an existing branch (e.g. git checkout master).
You can also use git reset: see What's the difference between 'git reset' and 'git checkout'?, and also "HEAD and ORIG_HEAD in Git"

0
0

You can use git reset --hard HEAD to throw away all your changes that you haven't committed, including on disk, but it's hard to tell if that's what you want here. Posting the output of git status and the output of the commands you've already tried would help a lot

Not the answer you're looking for? Browse other questions tagged or ask your own question.