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
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
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With