简体   繁体   中英

Accidentally stopped command in middle of git checkout how do I recover

I ran git checkout and stopped the process in the middle. 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: ...

I tried

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.

WARNING This is the most common way to lose work in 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. It is only available as of version 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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