Git pull 与章鱼策略冲突

Jan*_*mar 6 git remote-branch branching-and-merging

最近,当我在 master 分支中运行时,git pull它偶尔会出现以下合并错误:

   Trying simple merge with 7ff9b5...
   Trying simple merge with 6872cd...
   Simple merge did not work, trying automatic merge.
   Auto-merging file.txt
   ERROR: content conflict in file.txt
   fatal: merge program failed
   Automated merge did not work.
   Should not be doing an Octopus.
   Merge with strategy octopus failed.
Run Code Online (Sandbox Code Playgroud)

然而,在这次合并尝试之后,有些文件甚至不在主分支中。我可以使用git reset并再次拉动来解决这个问题,但我想知道这个头或提交来自哪里,我怎样才能找到这个?我尝试查看gitk并检查本地 GitLab 服务器,但找不到任何内容。

Chr*_*ris 3

您应该能够查看单个文件的历史记录git log <filename>。这可能有助于识别您的神秘文件。

对于冲突,应使用冲突标记显示冲突来源:

<<<<<<< HEAD:filename
...
=======
...
>>>>>>> abcd123:filename
Run Code Online (Sandbox Code Playgroud)

它还可能有助于从git pull工作流程切换到git fetch工作流程。

fetch更新您的远程分支指针(例如origin/master),但不会自动合并您的本地分支(例如master)。然后,您可以用来gitk --all直观地比较分支、git diff origin/master查看终端中的更改等。

一旦您满意并想要合并上游更改,您所需要做的就是合并(例如git merge origin/mastermaster分支合并)。一般情况下,后面git pull跟着git fetchgit merge.