Git错误地将冲突标记为已解决

时间:2015-04-28 20:00:42

标签: git merge-conflict-resolution

有些事情导致Git自动“解决”合并冲突。

下面是尝试合并的实际行输出行:

>> git status
On branch BRANCH-A
Your branch is up-to-date with 'origin/BRANCH-A'.
nothing to commit, working directory clean
>> git merge BRANCH-B
Auto-merging file1.css
CONFLICT (content): Merge conflict in file1.css
Auto-merging file2.css
Auto-merging file3.scss
CONFLICT (content): Merge conflict in file3.scss
Auto-merging file4.js
CONFLICT (content): Merge conflict in file4.js
Removing file5.js
Auto-merging file6.json
CONFLICT (add/add): Merge conflict in file6.json
Auto-merging file7.jsp
CONFLICT (content): Merge conflict in file7.jsp
Auto-merging file8.java
CONFLICT (content): Merge conflict in file8.java
Auto-merging file9.java
CONFLICT (content): Merge conflict in file9.java
Auto-merging file10.java
CONFLICT (content): Merge conflict in file10.java
Automatic merge failed; fix conflicts and then commit the result.
>> git st
On branch BRANCH-A
Your branch is up-to-date with 'origin/BRANCH-A'.
You have unmerged paths.
(fix conflicts and run "git commit")

Changes to be committed:

modified:   .gitignore
modified:   web.xml
deleted:    file5.js
new file:   someFile.js
renamed:    otherFile.css -> anotherFile.css

Unmerged paths:
(use "git add <file>..." to mark resolution)

both modified:   file8.java
both modified:   file7.jsp
both added:      file6.json
both modified:   file4.js
both modified:   file3.scss
both modified:   file1.css

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified:   file9.java
modified:   file10.java

>> git st
On branch BRANCH-A
Your branch is up-to-date with 'origin/BRANCH-A'.
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)

Changes to be committed:

modified:   .gitignore
modified:   web.xml
deleted:    file5.js
new file:   someFile.js
renamed:    otherFile.css -> anotherFile.css

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified:   file8.java
modified:   file9.java
modified:   file10.java
modified:   file7.jsp
modified:   file6.json
modified:   file4.js
modified:   file3.scss
modified:   file1.css

我知道这有点冗长,但我想强调的是,这就是我所做的一切:合并,检查git状态,然后再次检查git状态。我第二次检查git状态时表示所有冲突都已解决。或者,如果我在尝试合并后立即运行git mergetool(并且我的屏幕充满了CONFLICT消息),我会收到No files need merging消息。

我完全没有找到任何其他人的记录。我唯一能找到的是关于trustExitCode的一些git配置选项。但是,这些都没有。为了覆盖我的所有基础,这是我的~/.gitconfig文件。

[color]
    ui = true
[core]
    editor = vim
    excludesfile = /Users/ganders/.gitignore_global
[alias]
    st = status
    co = checkout
    br = branch
    cm = commit
    logtree = log --graph --decorate --abbrev-commit --pretty=format:'%C(auto)%h%Creset%C(auto)%d%Creset %s %Cgreen(%cr)%C(blue) [%an]%Creset'
[push]
    default = simple
[credential]
    helper = osxkeychain
[merge]
    tool = opendiff
[mergetool "opendiff"]
    cmd = /usr/bin/opendiff
    trustExitCode = false
[difftool "sourcetree"]
    cmd = opendiff \"$LOCAL\" \"$REMOTE\"
    path = 
    trustExitCode = false
[mergetool "sourcetree"]
    cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
    trustExitCode = false

我在命令行和SourceTree上使用git之间交替。我的命令行版本的Git是从Homebrew安装的2.3.6。我已经尝试过卸载并重新安装git以及删除和重新克隆我的git存储库,所有这些都没有运气。

2 个答案:

答案 0 :(得分:0)

  

所有冲突都已修复,但您仍在合并。 (使用“git commit”来   总结合并)

基于消息。我认为您需要添加所有更改并提交相关文件。

答案 1 :(得分:0)

我也被类似的 mergetool /&#34困扰了;今天没有文件需要合并&#34; 的情况,在Windows上使用git。

所以,我尝试了一下,找到&#34;没有文件需要合并&#34; 消息的打印位置。

原来是 git-mergetool ,一个shell脚本。

if test -z "$files"
then
    echo "No files need merging"
    exit 0
fi

$ files 的值之前设置了一些行:
(在if-branch下,取决于参数的数量,或rerere设置)

files=$(git rerere remaining)
files=$(git ls-files -u | sed -e 's/^[^    ]*    //' | sort -u)
files=$(git ls-files -u -- "$@" | cut -f 2 | sort -u)

我的情况有点连线 - 似乎 git ls-files 没有同步返回;分配后我不得不添加一些延迟,然后 $ files 不会为空。

我没时间进一步挖掘。希望这样的经历会有所帮助。