Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git simple conflicts automatic resolution

According to JetBrains IDEs (IntelliJ IDEA, etc.), simple conflicts means non-overlapping character changes within the same line:

For simple conflicts (for example, if the beginning and the end of the same line have been modified in different file revisions), the Resolve simple conflicts the Resolve simple conflicts button button that allows merging the changes in one click becomes available.

The JetBrains IDE suite gives a way to solve such simple conflicts automatically by clicking on a magic wand icon, when resolving Git conflicts.

Example:

States Result
Original This is a line that illustrate simple conflicts.
Change 1 This is a beautiful line that illustrate simple conflicts.
Change 2 This is a line that illustrate not so simple conflicts.
Final (magic wand) This is a beautiful line that illustrate not so simple conflicts.

Is there a way to tell Git to automatically resolve such simple conflicts?


To reproduce a simple conflict:

mkdir test-simple-conflicts
cd test-simple-conflicts
git init

echo "This is a line that illustrate simple conflicts." > sample.txt
git add sample.txt && git commit -m "Original"
git checkout -b change-1

echo "This is a beautiful line that illustrate simple conflicts." > sample.txt
git add sample.txt && git commit -m "Change 1"
git checkout -

echo "This is a line that illustrate not so simple conflicts." > sample.txt
git add sample.txt && git commit -m "Change 2"
git merge change-1

# The simple conflict happens here.

git merge --abort
like image 896
jbaptperez Avatar asked Nov 27 '25 14:11

jbaptperez


1 Answers

No, Git does not support such automatic functionality; its merge resolution algorithms work line-based. Maybe it could be solved by writing a custom merge driver, but I'm not aware of such a driver existing.

Even IntelliJ doesn't resolve such conflicts automatically, but requires you to click the icon next to each conflicting line pair.

Related: If git can figure out how to merge vertical (line) changes, why not horizontal (character) changes?

like image 130
knittl Avatar answered Nov 30 '25 06:11

knittl