开发者

How do I find back a commit in Git?

Here's what I did..

  • I checked out a previous commit (2 commits ago)
  • I modified files
  • Committed those files
  • Accidentally went back to the master branch

How do I get back to the files 开发者_如何学GoI committed without knowing the commit id ?


You can look at the reflog for HEAD. Two ways of doing so:

  • git reflog show HEAD (manpage)
  • Or open the text file ./git/logs/HEAD

This will show you the commits that you recently made, no matter what branch (or lack thereof) they are in.

Suppose you found the lost commit and its hash is 0123ab. You can either checkout it (git checkout 0123ab), or your can merge it into master (git checkout master; git merge 0123ab).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜