不需要的自动 Git 合并

  • 本文关键字:Git 合并 不需要 git
  • 更新时间 :
  • 英文 :

文件

WindowsFormsControlLibrary/Properties/licenses.licx在我的本地存储库中,在远程存储库中出错。

我放了*.licx in .gitignore文件。

当我使用命令 git pull 时,我收到以下消息:

error: Your local changes to the following files would be overwritten by merge:
    WindowsFormsControlLibrary/Properties/licenses.licx
Please, commit your changes or stash them before you can merge.

中止

做一个提交,我这样做:

$ git rm --cached WindowsFormsControlLibrary/Properties/licenses.licx
$ git --skip-worktree WindowsFormsControlLibrary/Properties/licenses.licx
$ git --assume-unchanged WindowsFormsControlLibrary/Properties/licenses.licx
$ git reset --hard HEAD

但是当我使用git pull时,消息是相同的。

如何在不必合并licenses.licx文件的情况下使用 git pull

您是否在本地更新了.gitignore?如果是这样,您必须检查全局 gitignore 文件的内容,这些文件有时会影响您的本地 gitignore。

当您执行git reset --hard HEAD 时,您撤消了从缓存中删除许可证文件的操作。再做一次git rm --cached WindowsFormsControlLibrary/Properties/licenses.licx,然后做一个git commit

为了安全起见,请在下一步之前制作本地 licenses.licx 文件的备份副本。

当您进行下一次拉取时,将出现合并冲突,因为您已经删除了文件,同时其他人显然已经更改了它(否则您不会收到原始错误)。使用"我的"解决它(或只是再次将其从缓存中删除)并提交。

请注意,这将在其他人的计算机上删除 licenses.licx 文件,当他们执行git pull 时。

最新更新