如何在git中找到具有意外冲突的合并?
在下面的示例中,我在master的头部生成了一个“奇怪”的合并——它更改了一个没有冲突的文件。Git似乎不喜欢告诉我我已经这么做了如何在git中找到具有意外冲突的合并?,git,merge,Git,Merge,在下面的示例中,我在master的头部生成了一个“奇怪”的合并——它更改了一个没有冲突的文件。Git似乎不喜欢告诉我我已经这么做了 git init test cd test seq 1 5 > file1 git add file1 seq 6 10 > file2 git add file2 git commit -m root git branch branch sed -i 's/7/8/' file2 git commit -a -m '7++' git checkout
git init test
cd test
seq 1 5 > file1
git add file1
seq 6 10 > file2
git add file2
git commit -m root
git branch branch
sed -i 's/7/8/' file2
git commit -a -m '7++'
git checkout branch
sed -i 's/7/6/' file2
sed -i 's/3/4/' file1
git commit -a -m '7--; 3++'
git checkout master
git branch oldmaster
git merge branch
git checkout master file1
git checkout branch file2
git commit
显然,产生这个问题的过程是不寻常的,但假设不是我造成的,我怎么能找到它呢?git日志没有帮助;它甚至没有显示我选择了哪些冲突:
git log -p --graph
* commit cde4ac55b4c60d5c5c7f36bae9d9cc34689b20c1
|\ Merge: 8689e18 f42deb9
| | Author: David Buckley <bucko@gambitresearch.com>
| | Date: Tue Dec 9 12:29:51 2014 +0000
| |
| | Merge branch 'branch'
| |
| | Conflicts:
| | file2
| |
| * commit f42deb9971ca05afbff11bb5dcc77650585c990b
| | Author: David Buckley <bucko@gambitresearch.com>
| | Date: Tue Dec 9 12:29:51 2014 +0000
| |
| | 7--; 3++
| |
| | diff --git a/file1 b/file1
| | index 8a1218a..6234030 100644
| | --- a/file1
| | +++ b/file1
| | @@ -1,5 +1,5 @@
| | 1
| | 2
| | -3
| | +4
| | 4
| | 5
| | diff --git a/file2 b/file2
| | index 1e1140b..63f0f17 100644
| | --- a/file2
| | +++ b/file2
| | @@ -1,5 +1,5 @@
| | 6
| | -7
| | +6
| | 8
| | 9
| | 10
| |
* | commit 8689e183d785af50dd2f92e3d7bed3b62507447f
|/ Author: David Buckley <bucko@gambitresearch.com>
| Date: Tue Dec 9 12:29:51 2014 +0000
|
| 7++
|
| diff --git a/file2 b/file2
| index 1e1140b..6f1177a 100644
| --- a/file2
| +++ b/file2
| @@ -1,5 +1,5 @@
| 6
| -7
| +8
| 8
| 9
| 10
|
* commit bb2a50a7164ffe79a2fc26d0008ca4fe26b07442
Author: David Buckley <bucko@gambitresearch.com>
Date: Tue Dec 9 12:29:51 2014 +0000
root
diff --git a/file1 b/file1
new file mode 100644
index 0000000..8a1218a
--- /dev/null
+++ b/file1
@@ -0,0 +1,5 @@
+1
+2
+3
+4
+5
diff --git a/file2 b/file2
new file mode 100644
index 0000000..1e1140b
--- /dev/null
+++ b/file2
@@ -0,0 +1,5 @@
+6
+7
+8
+9
+10
git log-p——图形
*提交cde4ac55b4c60d5c5c7f36bae9d9cc34689b20c1
|\合并:8689e18 f42deb9
||作者:大卫·巴克利
|日期:2014年12月9日星期二12:29:51+0000
| |
||合并分行“分行”
| |
||冲突:
||文件2
| |
|*提交f42deb9971ca05afbff11bb5dcc77650585c990b
||作者:大卫·巴克利
|日期:2014年12月9日星期二12:29:51+0000
| |
| | 7--; 3++
| |
|| diff--git a/file1 b/file1
||索引8a1218a..6234030 100644
|--文件1
||+++b/文件1
| | @@ -1,5 +1,5 @@
| | 1
| | 2
| | -3
| | +4
| | 4
| | 5
|| diff——git a/file2 b/file2
||索引1e1140b..63f0f17 100644
|--文件2
||+++b/文件2
| | @@ -1,5 +1,5 @@
| | 6
| | -7
| | +6
| | 8
| | 9
| | 10
| |
*|提交8689E183D785AF50DD2F92E3D7BED3B6250747F
|/作者:大卫·巴克利
|日期:2014年12月9日星期二12:29:51+0000
|
| 7++
|
|diff—git a/file2 b/file2
|索引1e1140b..6f1177a 100644
|---a/file2
|++b/file2
| @@ -1,5 +1,5 @@
| 6
| -7
| +8
| 8
| 9
| 10
|
*提交bb2a50a7164ffe79a2fc26d0008ca4fe26b07442
作者:大卫·巴克利
日期:2014年12月9日星期二12:29:51+0000
根
diff—git a/file1 b/file1
新文件模式100644
索引0000000..8a1218a
---/dev/null
+++b/文件1
@@ -0,0 +1,5 @@
+1
+2
+3
+4
+5
diff—git a/file2 b/file2
新文件模式100644
索引0000000..1e1140b
---/dev/null
+++b/文件2
@@ -0,0 +1,5 @@
+6
+7
+8
+9
+10
问题在于,头部的合并提交将更改还原为file1,但git日志并没有表明这已经发生,甚至没有表明此合并是有趣的
git Dull看不到反转(它声称所有file1都可以归咎于初始提交),即使我将master合并到分支中而不是反向
在这种情况下,我可以通过使用'-m'强制每个父级进行差异来找到它,但如果在合并之前在两个分支上都做了大量工作,那么这几乎是无用的——不寻常的更改将被双方的合法更改淹没,并且每个父级中所做的每一个“正常”更改都将重复
很明显,“git merge”可能会在这里找到问题所在,因为提交与父级的不同之处在于,单是merge不会建议这样做。感觉上,差异输出的格式仅使用相关提交及其所有父级作为源信息。我更希望它还考虑到所有父级的合并基——在没有合并基的情况下,提供类似于'-m'的输出
我可以通过以下方式获得接近我想要的东西:
diff -u <(git diff oldmaster..master) <(git diff $(git merge-base oldmaster branch)..branch)
--- /proc/self/fd/11 2014-12-09 13:01:44.576808417 +0000
+++ /proc/self/fd/12 2014-12-09 13:01:44.576808417 +0000
@@ -1,10 +1,21 @@
+diff --git a/file1 b/file1
+index 8a1218a..6234030 100644
+--- a/file1
++++ b/file1
+@@ -1,5 +1,5 @@
+ 1
+ 2
+-3
++4
+ 4
+ 5
diff --git a/file2 b/file2
-index 6f1177a..63f0f17 100644
+index 1e1140b..63f0f17 100644
--- a/file2
+++ b/file2
@@ -1,5 +1,5 @@
6
--8
+-7
+6
8
9
diff-u我不太明白你的问题。git是否显示cde4ac55
help?此外,合并并不真的可疑;它按预期工作:合并将查看所有分支自其公共基础以来的总体更改,然后尝试同时应用这两个更改。只有当Git自己无法这样做时才会发生冲突(通常是在同一文件的同一位置发生多个更改的情况下)。当他合并提交时,Git是否能够正确识别新行的来源?我希望它能够,这基本上就是你要问的(“这些变化是从哪里来的?”),但我没有试过;git show的行为与git log相同——它要么什么也不显示(因为每个更改的部分都由一个父级负责),要么显示得太多。poke:merge在将不同分支中的修补程序还原为要合并的修补程序时“闻起来很难闻”。争论的不是冲突,而是git的diff输出删除了重要的更改。在git日志中列出了对file1的更改,但在主控中不存在,而且似乎没有办法让git日志来表达这一点。
diff -u <(git diff branch..master) <(git diff $(git merge-base oldmaster branch)..oldmaster)
--- /proc/self/fd/11 2014-12-09 13:02:05.680455766 +0000
+++ /proc/self/fd/12 2014-12-09 13:02:05.680455766 +0000
@@ -1,14 +1,14 @@
-diff --git a/file1 b/file1
-index 6234030..8a1218a 100644
---- a/file1
-+++ b/file1
+diff --git a/file2 b/file2
+index 1e1140b..6f1177a 100644
+--- a/file2
++++ b/file2
@@ -1,5 +1,5 @@
- 1
- 2
--4
-+3
- 4
- 5
+ 6
+-7
++8
+ 8
+ 9
+ 10