我怎样才能找到所有曾在一个Git仓库冲突合并? [英] How can I find all the merges that had conflicts in a Git repository?

查看:214
本文介绍了我怎样才能找到所有曾在一个Git仓库冲突合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个研究,研究开源项目合并。

I am working on a research to study merges in open source projects.

最近,我问<一个href=\"http://stackoverflow.com/questions/15637494/how-can-i-find-all-the-commits-that-have-more-than-one-parent-in-a-git-repositor\">How我可以找到所有在一个Git仓库有多个父提交?,并得到了很好的答案。

I recently asked How can I find all the commits that have more than one parent in a Git repository?, 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.

此外,这将是非常有用的,如果我能找到一个混帐或bash(grep的,AWK?)命令,让我只在同一行是由两个贡献者修改这些提交。

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.

的想法是要找到提交即不能自动解决。

The idea is to find commits that cannot be auto-resolved.

所以,我怎样才能找到所有曾在一个Git仓库冲突的合并?

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. 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的复位 - 硬,甚至 git的清洁-fdx 在每次迭代。请务必仅在包含未知与git没有重要文件的结帐运行它!

Note: this script checks out many different commits, and runs git reset --hard and even git clean -fdx in every iteration. Be sure to only run it in a checkout that contains no important files unknown to 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

这篇关于我怎样才能找到所有曾在一个Git仓库冲突合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆