【问题标题】:Git rejected updates. Pull not solving itGit 拒绝更新。拉不解决
【发布时间】:2018-02-21 20:56:08
【问题描述】:

我正在尝试推送到我的 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.

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

提前致谢,

埃里克

【问题讨论】:

  • 提示。删除文件并拉取 ;)
  • config/config.json 重命名为config/config.json__。然后拉并合并。之后将config/config.json__ 重命名为config/config.json。并承诺。 (不过用rebase比较好,但是用两个词来解释太难了)

标签: git push pull


【解决方案1】:

错误告诉您该文件未被跟踪。
当您执行git status 时,它是否显示为未跟踪?

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

在这种情况下,一种解决方案是使用git fetch 后跟git rebase origin/branch-name 将您的本地分支重新定位到远程分支上

这里可能会出现冲突,您需要先解决才能推送。

哦,在你可以变基之前你需要做git stash 来存储你本地未提交的更改(如果你有的话)。你可以使用git stash pop在rebase之后恢复它们

【讨论】:

    猜你喜欢
    • 2020-03-15
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 2023-03-26
    • 2020-09-17
    相关资源
    最近更新 更多