Git拒绝了更新。拉不解决它

时间:2018-02-21 20:56:09

标签: git push pull

我正在尝试推送我的GitHub回购。但是我收到以下错误:

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命令给出了这个错误:

The following untracked working tree files would be overwritten by merge:
        config/config.json
Please move or remove them before you can merge.

但我不想删除它,因为它是回购中的必备文件。我在互联网上看到我应该尝试推-f,但这会完全从我的仓库中删除该文件。 如何将我的下一个更改推送到其他文件,而不必担心这个config.json文件?

提前致谢,

埃里克

1 个答案:

答案 0 :(得分:0)

错误告诉您文件未跟踪 当你git status时,它是否显示为未跟踪?

如果需要,您需要执行git add config/config.json,然后执行提交和推送。但是,如果远程分支上的文件已更改,您将无法执行推送(Git将拒绝更新)。

在这种情况下,一种解决方案是使用git fetch后跟git rebase origin/branch-name

来重新定义远程分支上的本地分支

此处可能会出现需要解决的冲突,然后才能推送。

哦,在你可以改变之前,你需要做git stash来存储你当地未提交的更改(如果你有的话)。您可以使用git stash pop

在rebase之后恢复它们
相关问题