开发者

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

开发者 https://www.devze.com 2023-01-17 02:10 出处:网络
开发者_如何学JAVAI 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.
开发者_如何学JAVA

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.


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"


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

0

精彩评论

暂无评论...
验证码 换一张
取 消