可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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