William Abma
William Abma

Reputation: 495

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. Those branches change functionnality in the code.

When the version is ready, i.e., 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.

However, this does not give me potential conflicts that a merge would cause, only files modified by several branches.

Upvotes: 2

Views: 779

Answers (1)

Schleis
Schleis

Reputation: 43700

You could do git merge --no-commit and check the resulting conflicts. Then git reset --hard to remove the changes. 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):

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

Upvotes: 4

Related Questions