[英]Lost work doing a git checkout, how can I get it back
So... not sure how it happened, but I had been working in a branch a I made a couple changes, ran git add -A and then git commit (with a comment). 所以...不确定如何发生,但是我一直在分支机构工作,我做了一些更改,先运行git add -A然后进行git commit(带有注释)。 Did that a few times, and then when I went to push up all the changes to the branch I was in, I got a message that said that the branch was already up to date.
做了几次,然后当我将所有更改推送到我所在的分支时,我收到一条消息,说该分支已经是最新的。 I couldnt figure out what the heck was going on, so I checked back out the branch and it overwrote everything.
我无法弄清楚到底发生了什么,所以我检查了分支,发现它覆盖了所有内容。
Stranger still, now all the commits I made are gone when I run git log. 仍然很陌生,现在当我运行git log时,我所做的所有提交都消失了。
Any way I can get it all back? 有什么办法我可以把它还回来吗? Or am I SOL and have to figure out why the heck it kicked me out of my branch for some reason?
还是我是SOL,必须弄清楚为什么由于某种原因将它踢出了我的分支?
You are in a detached HEAD (see " Why did my Git repo enter a detached HEAD state? "). 您处于一个分离的HEAD中(请参阅“ 为什么我的Git回购进入了分离的HEAD状态? ”)。
You can confirm it with a git status
. 您可以使用
git status
进行确认。
Simply start by making a branch where you are: 只需在您所在的位置建立分支即可:
git branch tmp
See here one way to fix it (and keeping your commits) , if you want to push aBranch
: 如果要推送
aBranch
,请参见此处一种修复它(并保留提交)的 aBranch
:
git checkout aBranch
git merge tmp
aBranch
should now include the commits you did, and you should be able to push it. 现在,
aBranch
应该包括您所做的提交,并且您应该能够推送它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.