Git pull-请先移动或移除它们,然后再进行合并 [英] Git pull - Please move or remove them before you can merge
问题描述
我正在尝试从服务器上执行git pull origin master
,但始终收到错误消息:
I am trying to do a git pull origin master
from my server but keep getting the error:
Please move or remove them before you can merge.
没有未跟踪的文件,但是由于某些原因,似乎被忽略的文件出现了问题.
There are no untracked files, but it seems like it has issues with the ignored files for some reason.
我尝试运行git clean -nd
来查看要删除的内容,它列出了在.gitignore
中被忽略的一堆文件.
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
.
我该如何解决这个问题,以便进行拉拔?
How can I fix this so I can do a pull?
推荐答案
显然,无论源中.gitignore
文件的内容是什么,文件都是添加到远程存储库中的.
Apparently the files were added in remote repository, no matter what was the content of .gitignore
file in the origin.
由于文件存在于远程存储库中,因此git也必须将它们拉到本地工作树中,因此抱怨文件已经存在.
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.
.gitignore
仅用于扫描新添加的文件,与已添加的文件无关.
.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.
因此解决方案是删除工作树中的文件并提取最新版本.或者长远的解决方案是,如果文件是错误添加的,则从存储库中删除文件.
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 pull-请先移动或移除它们,然后再进行合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!