[英]How can I find all the merges that had conflicts in a Git repository?
I am working on a research to study merges in open source projects. 我正在研究开源项目中的合并。
I recently asked How can I find all the commits that have more than one parent in a Git repository? 我最近问过如何在Git存储库中找到所有具有多个父级的提交? , and got very good answers. ,并得到了很好的答案。
Now I need to narrow my query to only find the commits that had conflicts. 现在我需要缩小查询范围,只查找有冲突的提交。
With conflicts I mean that the same file was modified in two contributing commits. 对于冲突,我的意思是在两个贡献提交中修改了相同的文件。
Also, it would be very useful if I can find a git or bash (grep, awk?) command that gives me only those commits in which the same line was modified by two contributors. 另外,如果我能找到一个git或bash(grep,awk?)命令,它只会给我两个贡献者修改同一行的提交,这将非常有用。
The idea is to find commits that cannot be auto-resolved. 我们的想法是找到无法自动解决的提交。
So, How can I find all the merges that had conflicts in a git repository? 那么,我怎样才能找到git存储库中存在冲突的所有合并?
Once a merge commit is created, the information how the merge was performed is unfortunately lost. 一旦创建了合并提交,遗憾的是丢失了如何执行合并的信息。 This is important because git merge
accepts a number of options, such as strategy and per-strategy options, that affect appearance of conflicts. 这很重要,因为git merge
接受了许多影响冲突外观的选项,例如策略和每策略选项。 However, if your goal is to cover the reasonable case of finding merges that would have produced conflicts with the default merge options, it is possible to brute-force it: go over merge commits, recreate their merges, and flag the ones where git reports. 但是,如果您的目标是覆盖查找可能与默认合并选项发生冲突的合并的合理情况,则可以强制执行:转换合并提交,重新创建合并,并标记git报告的合并。
Note: this script checks out many different commits, and runs git reset --hard
and even git clean -fdx
in every iteration. 注意:此脚本检出许多不同的提交,并在每次迭代中运行git reset --hard
甚至git clean -fdx
。 Be sure to only run it in a checkout that contains no important files unknown to git! 一定要只在结帐中运行它,其中不包含git未知的重要文件!
#!/bin/bash
old_branch=$(git symbolic-ref --short HEAD)
for commit in `git rev-list --merges HEAD`
do
# find the parents of the merge commit
parents=$(git log -1 --format=%P $commit)
fst=${parents%% *}
rest=${parents#* }
# check out the first parent
git checkout -q $fst
# merge with the rest of them
git merge --no-commit $rest >/dev/null 2>&1
# if there are any conflicts, print the commit and abort the merge
if git ls-files --unmerged | grep -q '^'; then
echo $commit
git merge --abort
fi
# get rid of changes so the next checkout doesnt complain
git reset -q --hard
git clean -fdxq
done
git checkout -q $old_branch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.