简体   繁体   English

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

[英]Check for files changed in several branches before merging (conflicts) into master

The situation is the following: 情况如下:

I have a master branch, from which several dev branches are created. 我有一个master分支,从中创建了几个dev分支。 Those branches change functionnality in the code. 这些分支会更改代码中的功能。

When the version is ready, ie, all branches are available to merge, I do the merge. 版本准备好后,即所有分支都可以合并,我进行合并。 However, I want to be able to see before merging what files were modified at the same time by two branches in a conflicting way . 但是,在合并两个分支同时以冲突的方式修改了哪些文件之前,我希望能够看到。

This would allow me to be better prepared to handle the merge beforehand, as it can be time-consuming to keep both functionnalities. 这将使我能够更好地做好事前处理合并的准备,因为保留两个功能可能很耗时。

I agree with the fact that rebase should be done, but sometimes it is not possible (time frame), several developers working on the project at the same time. 我同意应该进行基准调整的事实,但有时是不可能的(时间框架),因为有多个开发人员同时从事该项目。

So, is there a way to get those files (and the branches/commits they come from), so that the merge could be done as early as possible ? 因此,有没有办法获取这些文件(以及它们来自的分支/提交),以便可以尽早进行合并?

My option for now is to get the output of git diff --name-status between master and each branch that I plan on merging (formatted Vxx/description), and get the doublons through a python script. 现在,我的选择是获取master和我计划合并的每个分支(格式为Vxx / description)之间的git diff --name-status输出,并通过python脚本获取doublons。

However, this does not give me potential conflicts that a merge would cause, only files modified by several branches. 但是,这不会给我带来合并可能引起的潜在冲突,仅提供由多个分支修改的文件。

You could do git merge --no-commit and check the resulting conflicts. 您可以执行git merge --no-commit并检查产生的冲突。 Then git reset --hard to remove the changes. 然后git reset --hard删除更改。 You would be able to script this so that it performs the action on each branch and outputs the list of files that are conflicting with each branch. 您将可以对此编写脚本,以便它在每个分支上执行操作并输出与每个分支冲突的文件列表。

You would be able to use the command from this answer to output the list of conflicted files. 您将能够使用此答案中的命令来输出冲突文件列表。

The bash script would look something like (sorry not able to make a one-liner for you): 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM