简体   繁体   English

进行git checkout时丢失了工作,我该如何找回它

[英]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.

相关问题 在没有git commit的情况下,如何在git add和git checkout之后找回我的差异? - How can I get my diff back after git add and git checkout without git commit? 使用Git for Windows - 意外地丢失了大量工作。 我能把它拿回来吗? - Using Git for Windows - Accidentally lost a ton of work. Can I get it back? 由于git reset --hard HEAD ^,我刚刚失去了两个星期的工作。 有什么办法找回来吗? - I just lost two weeks of work due to git reset --hard HEAD^. Any way to get it back? git checkout后,如何确保最后的提交不会丢失? - How to ensure the last commit(s) will not get lost after git checkout? Git:将提交发送到另一个分支,以便我可以工作并合并回去,而无需(非常慢)结帐? - Git: send commit to another branch so I can work and merge back, without (very slow) checkout? 如果我在分支上运行`git checkout - - .` 有什么方法可以让这些文件回来吗? - If I run `git checkout -​- .` on branch. Is there any way I can get those files back? GIT 我想取消我的结帐并返回未提交的更改? (我可以这样做吗?) - GIT I want to cancel my checkout and get not committed changes back ! (Can I do that ?) 在执行git checkout $ tag命令之前,如何检查间隔循环是否存在标签? - How can I check in interval loop if the tags exist before doing the `git checkout $tag` command? git checkout和git pull后如何找回修改后的文件? - How to get back modified file after git checkout and git pull? 我可以回到“ git checkout”状态之前吗? - Can I go back to prior to “git checkout” status?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM