我想查看存储库的历史记录,看看过去发生了哪些类型的合并冲突。
我尝试使用git log --merges
,但这似乎表明合并成功。
答案 0 :(得分:2)
我认为您可以从git-rerere中受益,并结合以前的培训知识来解决问题:
我认为实际的存储位置在.git/rr-cache
中,但是我从没看过,也不知道其中有什么。
答案 1 :(得分:2)
除非您启用了rerere,否则Git不会记录合并冲突,但是它会记录重新创建冲突所需的大多数信息。您可以编写脚本来重新创建合并冲突,但有一些警告... Git不会记录您用于解决合并的合并策略,因此您将不得不希望默认策略是明智的选择,或者进行一些调整以便将其用于您的存储库。
您可以列举与rev-list
的合并:
git rev-list --parents --min-parents=2 --all
这比git log
更可取,因为输出适用于脚本解析。这将产生合并提交的列表,每行一个。子提交是第一个哈希,其余哈希是父母。例如,
28171e725cc93e8cb85194931e7138c31f980a43 20af81cf6388026ecf0de4eec8783e7a38905ccd 2d77896f5fcc1a9b09f4f099aa6e945e8da86410
这里,合并是在20af和2d77之间。
以分离的头签出第一个父母:
git checkout -q --detach 20af81cf6388026ecf0de4eec8783e7a38905ccd
然后合并其余的父母:
git merge -q --no-commit --no-ff 2d77896f5fcc1a9b09f4f099aa6e945e8da86410
如果有冲突,merge
的状态码将为1,您可以检查一下。如果存在合并冲突,您会看到UU
处于瓷器状态的文件:
git status --porcelain
然后您可以中止合并以将其重置为可以使用存储库的状态:
git merge --abort
我已将其转换为演示脚本。该脚本必须在原始存储库上运行,因为它将运行一堆git checkout
和git merge
命令。
https://gist.github.com/depp/f1838cf4559f9cde74b9d3052b8abbb0
该脚本将使用默认策略重试历史记录中的所有合并,并报告冲突文件。
如果愿意,可以轻松扩展脚本以复制冲突文件,以便查看冲突。
答案 2 :(得分:1)
不容易..但是如果您需要...,您可以关闭脚本。
您可以使用git log查找所有合并提交-假设您保留了自动消息,或者使用(希望)始终相同的明智消息。例如:
git log --all --oneline --graph --decorate
生成仓库的一个体面的树状视图-例如:
* a1a9bde (HEAD -> TESTER) Merge branch 'test' into TESTER
|\
| * 2ff3965 (test) updated
| * 12af0b0 s
* | eb9ab80 updated
* | bec65ad (master) Merge branch 'master' of d:\software\sandpit\git-test
|\ \
| * \ 595bff6 Merge branch 'master' of d:\software\gitRepos\git-test
| |\ \
| | * | 77d69c7 new file
| | |/
:
但是对于脚本编写,只需使用git log --oneline --all
:
a1a9bde Merge branch 'test' into TESTER <----- LETS LOOK AT THIS MERGE...
eb9ab80 updated
2ff3965 updated
bec65ad Merge branch 'master' of d:\software\sandpit\git-test
8a73cd1 updated test1
58080f2 new file
819226c new file
e122cc6 file for merge back to master
49acb0b file added in branch
a262470 yet another file
12af0b0 s
或者仅获取哈希列表:git log --oneline --all | grep "Merge branch" | awk '{print $1}'
:
a1a9bde
bec65ad
更新1
或作为Dietrich Epp
(几乎)建议使用git rev-list --min-parents=2 a1a9bde
-这给出了具有2个父母的任何提交的完整哈希值-不错的Dietrich Epp
!
更新1-结束
现在循环遍历这些散列,例如从这里使用第一个:a1a9bde
您可以获取父哈希,例如:git show --format="%P" 595bff6
-这个等级:
eb9ab8029e6951f68a9c1008bb8611444d31528d 2ff3965b9aa1e6c49c82127e5f08199796a40780
现在,您可以通过以下方式运行模拟合并:
签出第一个哈希:git checkout eb9ab8029e6951f68a9c1008bb8611444d31528d -B merge_test
-这会将第一个哈希签出到名为merge_test
的分支上(并替换以前的任何同名分支)
合并第二个哈希(空运行):git merge --no-commit --no-ff 2ff3965b9aa1e6c49c82127e5f08199796a40780
git status | grep "both modified"
查看冲突-给出: both modified: testfile1.txt <---- THIS FILE IS A CONFLICT
git merge --abort
整理一下所以无论如何-这有点痛苦,但这都可以很容易地编写脚本,我提供了执行该命令的命令,但是我没有动力编写脚本...:o
答案 3 :(得分:0)
您可以使用以下快速概述:
git log --merges --cc --all
--cc
选项是(来自git help log
):
-c
With this option, diff output for a merge commit shows the
differences from each of the parents to the merge result
simultaneously instead of showing pairwise diff between a parent
and the result one at a time. Furthermore, it lists only files
which were modified from all parents.
--cc
This flag implies the -c option and further compresses the patch
output by omitting uninteresting hunks whose contents in the
parents have only two variants and the merge result picks one of
them without modification.
这将显示冲突,但是-AFAICT-有关“附近的冲突”的更多信息。