简体   繁体   English

git-恢复通过检出删除的提交

[英]git - Recover commits that were deleted with checkout

I was 2 commits ahead of Github. 我比Github提前2次提交。 I did git checkout and these commits were deleted. 我做了git checkout ,这些提交被删除了。 I tried recover the files in .git folder to a previous version using the Dropbox history. 我尝试使用Dropbox历史记录将.git文件夹中的文件恢复到以前的版本。 I ran git status and showed that I was again 2 commits ahead, I got happy, commited and pushed to Github only to see that I didn't recover at all. 我运行git status并显示我再次领先2次提交,我感到高兴,坚定并推向Github只是看到我根本没有康复。

tl;dr : Lost 2 commits with git checkout tl; dr :丢失2次并提交git checkout

Just use git reflog to recover the commits. 只需使用git reflog即可恢复提交。

  1. Run git reflog 运行git reflog
  2. Pick a reflog commit id that is just before the checkout 选择恰好在结帐前的reflog提交ID
  3. Run git reset --hard commit_id_before_checkout to get to a state just before you ran git checkout . 运行git reset --hard commit_id_before_checkout ,使其在运行git checkout .之前进入一种状态git checkout .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM