Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Git存储库中找到所有发生冲突的合并?_Git_Version Control_Awk_Grep - Fatal编程技术网

如何在Git存储库中找到所有发生冲突的合并?

如何在Git存储库中找到所有发生冲突的合并?,git,version-control,awk,grep,Git,Version Control,Awk,Grep,我正在研究开源项目中的合并 我最近问了,得到了很好的回答 现在我需要缩小查询范围,只查找有冲突的提交 对于冲突,我的意思是同一个文件在两次提交中被修改 另外,如果我能找到一个git或bash(grep,awk?)命令,它只给我那些由两个贡献者修改了同一行的提交,那将非常有用 其思想是查找无法自动解析的提交 那么,如何在git存储库中找到所有发生冲突的合并?一旦创建了合并提交,很遗憾,执行合并的信息就丢失了。这一点很重要,因为git merge接受许多影响冲突外观的选项,例如策略和每策略选项。但是

我正在研究开源项目中的合并

我最近问了,得到了很好的回答

现在我需要缩小查询范围,只查找有冲突的提交

对于冲突,我的意思是同一个文件在两次提交中被修改

另外,如果我能找到一个git或bash(grep,awk?)命令,它只给我那些由两个贡献者修改了同一行的提交,那将非常有用

其思想是查找无法自动解析的提交


那么,如何在git存储库中找到所有发生冲突的合并?

一旦创建了合并提交,很遗憾,执行合并的信息就丢失了。这一点很重要,因为
git merge
接受许多影响冲突外观的选项,例如策略和每策略选项。但是,如果您的目标是涵盖查找可能与默认合并选项产生冲突的合并的合理情况,则可以强制执行:检查合并提交,重新创建它们的合并,并标记git报告的合并

注意:此脚本检查许多不同的提交,并在每次迭代中运行
git reset--hard
甚至
git clean-fdx
。确保只在不包含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

如果有人感兴趣,我也会问Mercurial同样的问题:谢谢用户4815162342!这正是我需要的。