为什么git revert在这个例子中失败了?

Mac*_*Mac 5 git

一位同事正在玩git revert今天他结束了一个奇怪的情况:

git init
echo 1 > file.txt
git add file.txt
git commit -m "Commit 1"
# Say this generates hash aaa

cat file
1

echo 2 >> file.txt
git add file.txt
git commit -m "Commit 2"
# Say this generates hash bbb

cat file
1
2

echo 3 >> file.txt
git add file.txt
git commit -m "Commit 3"
# Say this generates hash ccc

cat file
1
2
3

git revert bbb
#line above does not work
Run Code Online (Sandbox Code Playgroud)

恢复工作不起作用,并最终采取樱桃挑选的情况.我期待以下结果:

cat file
1
3
Run Code Online (Sandbox Code Playgroud)

diff -R工作正常

diff --git b/file.txt a/file.txt
index aaa..bbb 100644
--- b/file.txt
+++ a/file.txt
@@ -1,2 +1 @@
 1
-2
Run Code Online (Sandbox Code Playgroud)

这可能是非常愚蠢的事情,但是什么呢?

Die*_*Epp 3

这只是合并冲突的相反过程。取消合并冲突?您可以将恢复视为合并的反面。如果您尝试以相反的方向执行相同的操作,则会出现合并冲突。

$ git init
Initialized empty Git repository in /home/depp/test/.git/
$ echo 1 > file.txt
$ git add .
$ git commit -m A
[master (root-commit) 406d008] A
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt
$ echo 2 >> file.txt
$ git add .
$ git commit -m B
[master 730fed9] B
 1 file changed, 1 insertion(+)
$ git branch branch1 'HEAD^'
$ git checkout branch1
Switched to branch 'branch1'
$ echo 3 >> file.txt
$ git add .
$ git commit -m C
[branch1 c359c04] C
 1 file changed, 1 insertion(+)
$ git merge master
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
Run Code Online (Sandbox Code Playgroud)

您可能认为答案是“显而易见的”,甚至可能想向 Git 开发人员提交错误或增强请求,但 Git 并不认为答案是显而易见的。Git 认为你应该把“3”放在“2”后面,但是现在没有“2”,那么你应该把“3”放在哪里呢?

如果某个更改的上下文不存在,Git 会向您寻求帮助,这是有一定道理的,因为在这些情况下您可能需要进行手动修复。

联盟合并?

merge=union我尝试在.gitattributesfor中指定file.txt,但这最终导致恢复根本不执行任何操作。诡异的。