Git 拒绝更新.拉不解决 [英] Git rejected updates. Pull not solving it
问题描述
我正在尝试推送到我的 GitHub 存储库.但我收到以下错误:
I'm trying to push to my GitHub repo. But I get the following error:
Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
我认为这与/config/config.json 文件有关.这个文件在我的 .gitignore 里面,但我在 GitHub 网站上手动添加了一次,并删除了里面的密码.pull 命令给了我这个错误:
I think it has to do with a /config/config.json file. This file is inside my .gitignore, but I added it for once and for all manually on the GitHub website and removed the passwords inside it. The pull command gives me this error:
The following untracked working tree files would be overwritten by merge:
config/config.json
Please move or remove them before you can merge.
但我不想删除它,因为它是 repo 中必不可少的文件.我在互联网上读到我应该尝试 push -f,但这会从我的仓库中完全删除该文件.如何将我的下一个更改推送到其他文件,而不必担心这个 config.json 文件?
But I don't want to remove it, because it is an essential file in the repo. I read on the internet I should try push -f, but this removes that file from my repo completely. How can I push my next changes to other files, without having to worry about this config.json file?
提前致谢,
埃里克
推荐答案
该错误告诉您该文件未被跟踪.
当您执行 git status
时,它是否显示为未跟踪?
The error tells you that the file is untracked.
Does it show as untracked when you do git status
?
如果是这样,您需要执行 git add config/config.json
然后是提交和推送.但是,如果远程分支上的文件已更改,您将无法进行推送(Git 将拒绝更新).
If so you need to do git add config/config.json
followed by a commit and a push. However, if the file has changed on the remote branch you will not be able to do the push (Git will reject the updates).
在这种情况下,一种解决方案是使用 git fetch
后跟 git rebase origin/branch-name
In that case one solution is to rebase your local branch on the remote branch with git fetch
followed by git rebase origin/branch-name
这里可能会出现冲突,您需要先解决才能推送.
Here conflicts may appear that you need to resolve before you can push.
哦,在你可以 rebase 之前,你需要做 git stash
来存储本地未提交的更改(如果有的话).您可以在使用 git stash pop
Oh, and before you can rebase you need to do git stash
to stash your local uncommitted changes (if you have any). You can restore them after the rebase with git stash pop
这篇关于Git 拒绝更新.拉不解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!