git 切换分支时Git不删除文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3885850/
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 not removing files when switching branch
提问by baloo
Sometimes when switching branches using Git (version 1.7.2.1)
it does not seem to remove the files/directories I created specific to the branch I switched away from.
Neither does it list it as untracked when running git status
or any log entries for those files.
有时,当使用 Git(版本 1.7.2.1)切换分支时,它似乎并没有删除我创建的特定于我切换的分支的文件/目录。它也不会在运行时将其列为未跟踪git status
或这些文件的任何日志条目。
This only happens occasionally and I'm not sure why or how to reset it so the files not belonging to the current branch gets deleted. If I delete the files manually, it gets in sync again (as in gets deleted/revived when switching branch).
这只是偶尔发生,我不确定为什么或如何重置它,以便删除不属于当前分支的文件。如果我手动删除文件,它会再次同步(如切换分支时被删除/恢复)。
Anyone experienced this?
有人经历过吗?
回答by Chris Kooken
I have seen this too. I usually just do a git reset --hard
followed by a git clean -f -d
and it usually does the trick.
我也见过这个。我通常只做一个git reset --hard
后跟一个git clean -f -d
,它通常可以解决问题。
It seems to definitely happen the most often when my IDE has a lock on one of the files in the branch i'm switching from.
当我的 IDE 锁定我要切换的分支中的一个文件时,这似乎肯定是最常发生的。
回答by Anzumana Taal
First:
第一的:
git reset --hard
Reset the repository to the state of the last commit.
Since git normally does not remove files it is not tracking those could still cause issues.
将存储库重置为上次提交的状态。
由于 git 通常不会删除文件,因此不会跟踪那些仍可能导致问题的文件。
Then:
然后:
git clean -d --dry-run
See what files would get deleted. We don't want to loose valuable work. and if that is ok:
看看哪些文件会被删除。我们不想失去有价值的工作。如果没问题:
git clean -d
回答by Ousmane
I had the same problem because I did not commited files before switching branch !
我遇到了同样的问题,因为我在切换分支之前没有提交文件!
More explanations here : Why git keeps showing my changes when I switch branches (modified,added, deleted files) no matter if I run git add or not?
这里有更多解释:为什么无论我是否运行 git add ,当我切换分支(修改、添加、删除文件)时,git 总是显示我的更改?