Wally
Wally

Reputation: 13

How do I get back to my branch after local changes on an old commit?

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.

Upvotes: 1

Views: 605

Answers (2)

Daenyth
Daenyth

Reputation: 37461

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

Upvotes: 0

VonC
VonC

Reputation: 1327004

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"

Upvotes: 2

Related Questions