Git pull - 请在合并之前移动或删除它们
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36039687/
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 pull - Please move or remove them before you can merge
提问by Brett
I am trying to do a git pull origin master
from my server but keep getting the error:
我正在尝试git pull origin master
从我的服务器执行,但不断收到错误消息:
Please move or remove them before you can merge.
Please move or remove them before you can merge.
There are no untracked files, but it seems like it has issues with the ignored filesfor some reason.
没有未跟踪的文件,但似乎由于某种原因被忽略的文件存在问题。
I tried running a git clean -nd
to see what would be deleted and it lists a whole bunch of files that are ignored in .gitignore
.
我尝试运行 agit clean -nd
以查看将被删除的内容,它列出了.gitignore
.
How can I fix this so I can do a pull?
我该如何解决这个问题,以便我可以拉动?
采纳答案by Zbynek Vyskovsky - kvr000
Apparently the files were added in remote repository, no matter what was the content of .gitignore
file in the origin.
显然这些文件被添加到远程存储库中,无论.gitignore
源中文件的内容是什么。
As the files exist in the remote repository, git has to pull them to your local work tree as well and therefore complains that the files already exist.
由于文件存在于远程存储库中,git 也必须将它们拉到本地工作树中,因此会抱怨文件已经存在。
.gitignore
is used only for scanning for the newly added files, it doesn't have anything to do with the files which were already added.
.gitignore
仅用于扫描新添加的文件,与已添加的文件无关。
So the solution is to remove the files in your work tree and pull the latest version. Or the long-term solution is to remove the files from the repository if they were added by mistake.
所以解决方案是删除工作树中的文件并拉取最新版本。或者长期的解决方案是从存储库中删除错误添加的文件。
A simple example to remove files from the remote branch is to
从远程分支中删除文件的一个简单示例是
$git checkout <brachWithFiles>
$git rm -r *.extension
$git commit -m "fixin...."
$git push
Then you can try the $git merge
again
然后你可以再试$git merge
一次
回答by Neha
I just faced the same issue and solved it using the following.First clear tracked files by using :
我刚刚遇到了同样的问题并使用以下方法解决了它。首先使用以下方法清除跟踪文件:
git clean -d -f
then try git pull origin master
然后尝试 git pull origin master
You can view other git clean options by typing git clean -help
您可以通过键入查看其他 git clean 选项 git clean -help
回答by DURGESH
To remove & delete all changes git clean -d -f
删除和删除所有更改 git clean -d -f
回答by David
If there are too many files to delete, which is actually a case for me. You can also try the following solution:
如果要删除的文件太多,这对我来说实际上是一种情况。您也可以尝试以下解决方案:
1) fetch
1) 取
2) merge with a strategy. For instance this one works for me:
2)与策略合并。例如,这个对我有用:
git.exe merge --strategy=ours master
回答by Deepak G
If you are getting error like
如果你收到类似的错误
- branch master -> FETCH_HEAD error: The following untracked working tree files would be overwritten by merge: src/dj/abc.html Please move or remove them before you merge. Aborting
- 分支主 -> FETCH_HEAD 错误:以下未跟踪的工作树文件将被合并覆盖:src/dj/abc.html 请在合并前移动或删除它们。中止
Try removing the above file manually(Careful). Git will merge this file from master branch.
尝试手动删除上述文件(小心)。Git 将从 master 分支合并此文件。