问题描述
我正在尝试从远程存储库向本地发出Git提取请求,但是它在错误下方显示,并且我无法提取.
I am trying to make a Git pull request from the remote repository to local, but it shows below the error, and I am not able to pull.
例如 git pull origin master
:
error: The following untracked working tree files would be overwritten by merge:
db/development.sqlite3
db/test.sqlite3
log/development.log
log/test.log
tmp/cache/assets/C7D/310/sprockets%2F38d8bc4c0599099a0404900b377c353b
tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953
tmp/cache/assets/CDC/870/sprockets%2Fa77b26f54f3481a4b4daf08514b49074
tmp/cache/assets/CF0/DA0/sprockets%2Fd7d5b37686831d37c4dd75e645f5e016
tmp/cache/assets/D09/A10/sprockets%2Fd608b39f93a782efe7398ab3797f6948
tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705
tmp/cache/assets/D33/290/sprockets%2F94f084e7801a02e1fd62140be0f5e7cb
tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655
tmp/cache/assets/D57/600/sprockets%2Fec4b1ce010bcc065da023308f49a9d55
tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6
tmp/cache/assets/D6A/C30/sprockets%2Fd5b294a2f636c6ee22c18e24b19fdc41
tmp/cache/assets/D84/A20/sprockets%2Fd88ae988de6a691a6d472eee0441ad88
tmp/cache/assets/DCE/C90/sprockets%2Febaf322f09c9ee13f29fc061542fe6af
tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
tmp/cache/assets/E25/4C0/sprockets%2Fde2fd9fd11c04a582cdbbe3d84a35ae6
tmp/pids/server.pid
Please move or remove them before you can merge.
我现在才开始使用Git,不知道为什么会发生此错误.我该如何解决?
I just started using Git now and had no clue why this error happened. How do I resolve it?
推荐答案
您的工作树中有未跟踪的文件.那些列在您的帖子中.您尝试与 git pull
合并的某些提交将被合并覆盖.这不安全.这是不安全的,因为未跟踪这些文件,因此Git无法知道如何处理它们.它应该保留您拥有的文件并忽略传入的更改吗?它应该覆盖它们吗?它不可能知道,只有您知道.因此它拒绝做危险的事情.
You have untracked files in your working tree. Those listed in your post. Some of the commits you're trying to merge with git pull
would be overwritten by the merge. This is not safe. It cannot be safe, because these files are untracked, so Git cannot possibly know what to do with them. Should it keep the files you have and ignore the incoming changes? Should it overwrite them? It cannot possibly know, only you can know. So it refuses to do something dangerous.
通常,您需要将这些文件移开.例如,创建一个临时目录并将这些文件移到那里.或将它们放在备份文件中,然后从工作树中删除文件.
Normally, you need to move these files out of the way. For example, create a temporary directory and move these files there. Or put them in a backup file and delete the files from the working tree.
我通常写 ,因为这看起来很特殊.您的本地存储库是正确的,不会跟踪这些文件: tmp/*
看起来像临时缓存文件, log/*
文件看起来像日志文件,而 db/*
看起来像二进制数据库文件.通常,版本控制不应跟踪这些内容.但是,现在您正在尝试合并的远程存储库中已对它们进行了跟踪.看来开发人员犯了一个错误,并无意中将这些文件添加到了版本控制中.
I wrote normally, because this looks like a special case. Your local repository is correct that these files are not tracked: tmp/*
look like temporary cache files, log/*
files look like log files, and db/*
look like binary database files. None of these should be tracked by version control, normally. But they are tracked now in the remote repository you are trying to merge from. It looks like a developer made a mistake and added these files to version control by accident.
最好的办法是找到对这些文件进行过补偿的开发人员,并请他自己清理(因此他不会再这样做).在他从存储库中删除文件并再次推送之后,您的 git pull
命令将起作用.
The best thing to do is to find the developer who aded those files and ask him to clean up after himself (so he doesn't do it again). After he removes the files from the repository and pushes again, your git pull
command will work.
如果很难让作者解决存储库中的问题,则可以自己解决该问题:
If it's difficult to get the author to fix the problem in the repository, you can fix it yourself:
# create a clean clone to preserve your workspace
git clone URL /tmp/cleanup
cd /tmp/cleanup
# remove the junk
git rm -r db log tmp
# commit the fix (copy-pasted from @gturri's answer)
git commit -m "Removed binary and temporary files from Git"
git push
此后,您的 git pull
命令将起作用.
After this your git pull
command will work.
最后,应该在项目中正确配置 .gitignore
文件,这有助于防止此类错误.在您当前的工作区中,如果执行 git status
,并且看到 tmp
, log
, db
处于未跟踪状态,则表示不太好.这意味着这些目录不会被标记为被忽略,并且更容易犯此类错误并意外提交这些文件.在这种情况下,请更新您的 .gitignore
,这将使以后更难以出错.
Finally, something that should help preventing mistakes like this is correctly configured .gitignore
files in the project. In your current workspace, if you do git status
and you see tmp
, log
, db
as untracked, that's not so good. That means these directories are not marked to be ignored and it's easier to make mistakes like this and accidentally commit these files. In that case, update your .gitignore
, that will make it a lot harder to make a mistake like this in the future.
这篇关于git pull命令失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!