在合并(冲突)到master之前检查多个分支中的文件是否已更改

时间:2015-03-25 13:56:38

标签: git

情况如下:

我有一个主分支,从中创建了几个dev分支。这些分支改变了代码中的功能。

当版本准备就绪,即所有分支都可以合并时,我进行合并。但是,我希望能够在合并两个分支以相互冲突的方式同时合并哪些文件之前看到。

这将使我能够更好地准备好事先处理合并,因为保持两个功能都可能非常耗时。

我同意应该完成rebase的事实,但有时不可能(时间框架),几个开发人员同时在这个项目上工作。

那么,有没有办法获取这些文件(以及它们来自的分支/提交),以便尽可能早地完成合并?

我现在的选择是在master和我计划合并的每个分支(格式化Vxx / description)之间获取git diff --name-status的输出,并通过python脚本获得双倍。

但是,这并没有给我一个合并会导致的潜在冲突,只有几个分支修改了文件。

1 个答案:

答案 0 :(得分:2)

您可以执行git merge --no-commit并检查产生的冲突。然后git reset --hard删除更改。您可以编写脚本,以便它在每个分支上执行操作,并输出与每个分支冲突的文件列表。

You would be able to use the command from this answer to output the list of conflicted files.

bash脚本看起来像(抱歉不能为你制作一个单行):

git checkout master #make sure we are on master

#assuming checking all the branches but can use whatever list here
for branch in `git branch | grep -v master`
do
    echo "Conflicts for $branch"
    #do the merge and use the quiet option so nothing gets output until we want it
    git merge -q --no-commit $branch
    #list the conflicted files
    git diff --name-only --diff-filter=U
    #get rid of the changes
    git reset --hard master
done
相关问题