git 以下未跟踪的工作树文件将被合并覆盖: .gitignore 请在合并之前移动或删除它们
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28721185/
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
The following untracked working tree files would be overwritten by merge: .gitignore Please move or remove them before you can merge
提问by bCM
I been stuck with this problem for at least an hour. Trying to pull files with command.git pull
error: The following untracked working tree files would be overwritten by merge:
.gitignore
Please move or remove them before you can merge.
Aborting
我被这个问题困扰了至少一个小时。尝试使用命令拉取文件。git pull
错误:以下未跟踪的工作树文件将被合并覆盖:.gitignore 请在合并之前移动或删除它们。中止
I tried to remove it from my local map with rm .gitignore
我试图将它从我的本地地图中删除 rm .gitignore
回答by Chris
You've got a local, uncommitted .gitignore
file and the changes you're trying to pull contain a tracked.gitignore
file. Git is refusing to overwrite your .gitignore
with the upstream one because it can't give the old one back to you later (the file is untracked).
您有一个本地未提交的.gitignore
文件,并且您尝试提取的更改包含一个跟踪.gitignore
文件。Git 拒绝.gitignore
用上游的覆盖你的,因为它以后不能把旧的还给你(文件没有被跟踪)。
In general, I recommend using git fetch
instead of git pull
. This will update your local origin/master
, but not your local master
. Then you can compare the tracked .gitignore
in origin/master
with your local .gitignore
file. That's the only way to decide whether to keep one of them or merge them together.
一般来说,我建议使用git fetch
而不是git pull
. 这将更新您的本地origin/master
,但不会更新您的本地master
。然后,你可以比较跟踪.gitignore
在origin/master
您的本地.gitignore
文件。这是决定是保留其中一个还是将它们合并在一起的唯一方法。
Unfortunately, because your local .gitignore
isn't tracked it's a bit tricky to automate the comparison. I recommend committing it, then using git diff master..origin/master
or even just git merge origin/master
. Now that your .gitignore
is tracked, Git won't refuse the merge (but you may get a merge conflict that needs to be resolved).
不幸的是,因为您的本地.gitignore
没有被跟踪,所以自动比较有点棘手。我建议提交它,然后使用git diff master..origin/master
甚至只是git merge origin/master
. 现在您.gitignore
已被跟踪,Git 不会拒绝合并(但您可能会遇到需要解决的合并冲突)。
Note that in general .gitignore
shouldbe tracked. If you have ignores that shouldn't be tracked, put them in .git/info/exclude
instead.
请注意,一般.gitignore
应进行跟踪。如果您有不应该被跟踪的忽略,请将它们放入.git/info/exclude
。
回答by Joey Dorrani
Hello and welcome to Stack Overflow,
您好,欢迎来到 Stack Overflow,
I had this problem too.. The output surprised me:
我也有这个问题..输出让我感到惊讶:
error: The following untracked working tree files would be overwritten by merge:
index.php
Please move or remove them before you can merge.
I've read that this happens because you have local modifications which makes merging not possible.
我读到发生这种情况是因为您进行了本地修改,因此无法进行合并。
I've read that one of the solutions is to reset back to the head:
我读过其中一种解决方案是重置回头部:
git reset --hard HEAD
and then pull again:
然后再次拉:
git pull
You could also consider to commit first or stash your own changes.
您也可以考虑先提交或隐藏您自己的更改。
I am not sure, but have you already seen this question: git - strange branch merge error that I am not sure how to solve? Looks like Genadinik has the same problem.
我不确定,但您是否已经看过这个问题:git - 我不知道如何解决的奇怪分支合并错误?看起来 Genadinik 也有同样的问题。
Goodluck! I hope it helps you
祝你好运!我希望它能帮助你
回答by Rejo Varghese
Use git clean
command same error occurred to me so I used it. If you type
git clean -n
then you will get the list of items that will be removed.
if you use command
git clean -f
then it will get the list of untracked files and will remove the files
after using git clean -f
command then type git pull
it will pull the files from your repository.
Hope this is of help to you.
使用git clean
命令同样的错误发生在我身上,所以我使用了它。如果您键入,
git clean -n
那么您将获得将被删除的项目列表。如果您使用命令,
git clean -f
那么它将获取未跟踪文件的列表,并在使用git clean -f
命令后删除文件,然后键入git pull
它将从您的存储库中提取文件。希望这对你有帮助。