[英]Accidentally stopped command in middle of git checkout how do I recover
I ran git checkout and stopped the process in the middle. 我运行git checkout并在中间停止了该过程。 Now I can't switch branches because it complains I'll overwrite local files. 现在,我无法切换分支,因为它抱怨我将覆盖本地文件。 How do I get around this? 我该如何解决? eg 例如
git checkout egotailer error: Your local changes to the following files would be overwritten by checkout: ... git checkout egotailer错误:您对以下文件的本地更改将被checkout覆盖:...
I tried 我试过了
git clean -d -x -f git clean -d -x -f
but it didn't help 但这没有帮助
好吧,如果您知道自己的存储库是最新的,并且没有任何要检查的未完成操作,只需将分支重置为HEAD。
git reset --hard HEAD
git reset --hard
should do it. 应该这样做。 HEAD
is implied when you don't specify a reference. 如果您未指定参考,则表示HEAD
。
WARNING This is the most common way to lose work in Git!! 警告这是在Git中失去工作的最常见方式!
A safer way to clean your directory is 清理目录的更安全方法是
git stash -u
or 要么
git stash --include-untracked
This will do what git reset --hard
does but you can't accidentally lose information. 这将执行git reset --hard
操作,但是您不会意外丢失信息。 It is only available as of version 1.7.7. 仅从1.7.7版本开始可用。 Before that you had to 在此之前,您必须
git add -A && git stash
for the same effect. 具有相同的效果。
Later, if you realize you are missing important work, you can get it back from the stash. 以后,如果您发现自己缺少重要的工作,则可以将其从藏匿处取回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.