Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make git merge result in a conflict when both versions have the same change

Let's say in a git repo I have a file containing version information:

version=42

Now if on two separate branches the version is incremented to

version=43

and these branches are merged, the standard merge mechanism of git would not yield a merge conflict, since both versions are the same (even though the merge base is different).

Normally this is wanted behavior, but in the case of this file I want to get a merge conflict whenever both branches differ from the merge base. Is there any merge strategy that always ends in a merge conflict when a line is edited in both branches (even if they are the same)?

like image 470
jederik Avatar asked Dec 14 '17 10:12

jederik


People also ask

How do you trigger a merge conflict?

Often, merge conflicts happen when people make different changes to the same line of the same file, or when one person edits a file and another person deletes the same file. You must resolve all merge conflicts before you can merge a pull request on GitHub.

How do you resolve a merge conflict on the same branch?

The most common merge conflict scenario occurs when you pull updates from a remote branch to your local branch (for example, from origin/bugfix into your local bugfix branch). You can resolve these conflicts in the same way: create a commit on your local branch to reconcile the changes, and then complete the merge.


1 Answers

No. In fact, not only is there no such strategy built in to Git, the rest of Git's support routines—which you might want to use to write such a strategy—don't help you out here. Existing merge drivers mostly use git read-tree (or its internal equivalent) to perform as much of the work as possible inside the index, and it's git read-tree itself that collapses such results back to a fully merged stage zero entry, saving having to re-code that same thing into the recursive and resolve merge drivers.

The culprit code is here.

like image 60
torek Avatar answered Oct 21 '22 13:10

torek