git reset --hard HEAD leaves untracked files behind

匿名 (未验证) 提交于 2019-12-03 08:30:34

问题:

When I run git reset --hard HEAD, it's supposed to reset to a pristine version of what you pulled, as I understand it. Unfortunately, it leaves files lying around, as a git status shows a big list of untracked files.

How do you tell git "Just bring it back to EXACTLY what was in the last pull, nothing more, nothing less"?

回答1:

You have to use git clean -f -d to get rid of untracked files and directories in your working copy.



回答2:

If you have files you still want to keep:

git clean -di will do an interactive clean which allows you to only delete the files/dirs you don't want anymore.



回答3:

git reset --hard && git clean -dfx 

or, zsh provides a 'gpristine' alias:

alias gpristine='git reset --hard && git clean -dfx' 

Which is really handy



回答4:

User interactive approach:

git clean -i -fd  Remove .classpath [y/N]? N Remove .gitignore [y/N]? N Remove .project [y/N]? N Remove .settings/ [y/N]? N Remove src/com/amazon/arsdumpgenerator/inspector/ [y/N]? y Remove src/com/amazon/arsdumpgenerator/manifest/ [y/N]? y Remove src/com/amazon/arsdumpgenerator/s3/ [y/N]? y Remove tst/com/amazon/arsdumpgenerator/manifest/ [y/N]? y Remove tst/com/amazon/arsdumpgenerator/s3/ [y/N]? y 

-i for interactive
-f for force
-d for directory
-x for ignored files(add if required)

Note: Add -n or --dry-run to just check what it will do.



回答5:

The command you are looking for is git clean



回答6:

You might have done a soft reset at some point, you can solve this problem by doing

git add . git reset --hard HEAD~100 git pull 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!