【问题标题】:Deadlock between Git Pull & Git PushGit Pull 和 Git Push 之间的死锁
【发布时间】:2017-03-09 15:31:32
【问题描述】:

它是共享的 GIT 存储库。许多人在同一 git 存储库上工作。

这就是为什么我先尝试git pull 进行其他更改然后add, commit & push

我在本地尝试过以下命令

$ git pull
error: Your local changes to the following files would be overwritten by merge:

File Name

Please commit your changes or stash them before you can merge.
Aborting

提交

$ git commit

no changes added to commit

推送

$ git push
To ssh://git@ab.com:2222/diffusion/SMM/abc.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'ssh://git@ab.com:2222/diffusion/SMM/abc.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

如何解决这个问题?

【问题讨论】:

  • 通过 $git status 检查状态并添加和提交新的和修改过的文件,然后尝试 $git pull origin master
  • @AswathyS 究竟有什么帮助?!
  • @AnkitShah 你在提交之前尝试过添加吗?
  • 你是什么git status?它是否列出了未跟踪的文件?
  • @AnkitShah 你不明白哪一部分?您有本地更改。拉动会与这些变化发生冲突。您必须提交它们或还原它们。如果你想提交它们,你必须先添加它们(因此'使用“git add ...”来包含将要提交的内容')。

标签: git github ssh git-push git-pull


【解决方案1】:

所以您的问题是您的工作目录中有未跟踪的文件,您也尝试提取这些文件。

所以Some File 文件在您的工作目录中,但有人将同名文件推送到服务器。当您拉取时,它会使用远程存储库中的版本覆盖您的本地文件:Your local changes to the following files would be overwritten by merge

要解决这个问题,你可以做两件事:

  • 将文件移开,拉出,放置两个版本
  • git add 文件、git commit it 和 git pull 将您的本地更改与上游合并

另外,阅读staging area。您需要在提交之前将文件添加到暂存区域。这就是为什么git commit 告诉您没有任何准备提交的内容。 git commit 只提交您放入暂存区的内容。

【讨论】:

    【解决方案2】:

    我最近遇到了同样的问题。您可能忽略了此文件(.gitignore.git/info/exclude),或者您认为它没有更改(git update-index --assume-unchanged)。

    您可以使用git check-ignore -v "File Name" 来检查文件是否被忽略。 如果ls "File Name 没有返回错误,那么文件就在那里,但 git 假定它没有改变。您可以使用git update-index --no-assume-unchanged 假设它已更改。

    【讨论】:

    • .gitignore文件
    【解决方案3】:

    您应该花点时间了解 git 的工作原理(好资源 [1])。特别是,能够查看整个 git 历史记录至关重要,为此使用以下命令或 git UI (gitk, git-gui):

    git log --oneline --graph --all --decorate

    简而言之,可能:git pull --rebase 适合您(如果您没有冲突的更改)。

    [1]https://git-scm.com/book/en/v2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-24
      • 2021-09-12
      • 2016-04-08
      • 2012-09-07
      • 2014-03-09
      • 1970-01-01
      • 2020-10-20
      • 1970-01-01
      相关资源
      最近更新 更多