git reset --hard HEAD 留下未跟踪的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4327708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git reset --hard HEAD leaves untracked files behind
提问by Karl
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.
当我运行时git reset --hard HEAD
,它应该重置为您拉取的原始版本,据我所知。不幸的是,它会留下文件,因为agit status
显示了一大堆未跟踪的文件。
How do you tell git "Just bring it back to EXACTLY what was in the last pull, nothing more, nothing less"?
你如何告诉 git “只要把它带回上次拉取时的确切内容,不多不少”?
回答by knittl
You have to use git clean -f -d
to get rid of untracked files and directories in your working copy.
您必须使用git clean -f -d
删除工作副本中未跟踪的文件和目录。
If you need to reset the whole repository to master including all git submodules, run this script:
如果您需要将整个存储库重置为 master,包括所有 git 子模块,请运行以下脚本:
git reset --hard HEAD
git clean -f -d
git checkout master
git fetch origin master
git reset --hard origin/master
git pull
git submodule update
git submodule update --init --recursive
git submodule foreach git reset --hard HEAD
git submodule foreach git clean -f -d
git submodule foreach git submodule update --init --recursive
git submodule foreach git fetch
git submodule foreach git pull
git status
回答by Sogger
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.
git clean -di
将进行交互式清理,允许您只删除不再需要的文件/目录。
回答by jjnevis
git reset --hard && git clean -dfx
or, zsh provides a 'gpristine' alias:
或者,zsh 提供了一个“gpristine”别名:
alias gpristine='git reset --hard && git clean -dfx'
Which is really handy.
这真的很方便。
If working on a forked repo, make sure to fetch and reset from the correct repo/branch, for example:
如果在分叉的仓库上工作,请确保从正确的仓库/分支中获取和重置,例如:
git fetch upstream && git reset --hard upstream/master && git clean -df
回答by bit_cracker007
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 -nor --dry-runto just check what it will do.
-i 用于交互式
-f 用于强制
-d 用于目录
-x 用于忽略文件(如果需要添加)
注意:添加-n或--dry-run以检查它会做什么。
回答by Nikola Diklic
You can use git stash
. You have to specify --include-untracked
, otherwise you'll end up with the original problem.
您可以使用git stash
. 您必须指定--include-untracked
,否则您最终会遇到原始问题。
git stash --include-untracked
Then just drop the last entry in the stash
然后将最后一个条目放入藏匿处
git stash drop
You can make a handy-dandy alias for that, and call it git wipe
for example:
您可以为此创建一个方便的别名,并将其命名git wipe
为例如:
git config --global alias.wipe "! git stash -q --include-untracked && git stash drop -q"
回答by Jagriti Kumari
The command you are looking for is git clean
您正在寻找的命令是 git clean
回答by Yuresh Karunanayake
git-clean
Use to remove untracked files in the working tree. Following are some options (in brief) that can use with git clean
command.
git-clean
用于删除工作树中未跟踪的文件。以下是一些可以与git clean
命令一起使用的选项(简要)。
-d
use when no path is specified. So git recurse into untracked directories remove them.
-d
未指定路径时使用。所以 git recurse 进入未跟踪的目录删除它们。
-f/--force
To remove nested untracked files.
-f/--force
删除嵌套的未跟踪文件。
-i/--interactive
Show what would be done and clean files interactively.
-i/--interactive
显示将要完成的操作并以交互方式清理文件。
-n/--dry-run
Show what will happen without removing anything.
-n/--dry-run
显示不删除任何内容会发生什么。
-x
ignore files
-x
忽略文件
example: git clean -f -d
-> Remove all untracked files in current directory any subdirectories.
例如:git clean -f -d
-> 删除当前目录任何子目录中的所有未跟踪文件。
回答by user3780587
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