Sarthak Srivastav
Sarthak Srivastav

Reputation: 11

What is the original state in a conflict in git?

git config --global merge.conflictstyle diff3

I used this command while setting up my git on my Windows desktop but I don't know what this command does. My course stated that it is used to display the original state of conflict. Can anyone tell what does this mean?

Upvotes: 0

Views: 154

Answers (2)

Daly
Daly

Reputation: 879

The diff3 setting alters how merge conflicts are displayed. From the git merge-config man page:

The default [style] is "merge", which shows a <<<<<<< conflict marker, changes made by one side, a ======= marker, changes made by the other side, and then a >>>>>>> marker. An alternate style, "diff3", adds a ||||||| marker and the original text before the ======= marker.

Upvotes: 1

Ismail Shaheen
Ismail Shaheen

Reputation: 103

This original state you are talking about is what the code looks like in the ancestor node. For example, let's assume you have a git conflict and you didn't enable diff3, it would look something like this:

<<<<<<< HEAD
The changes you made
=======
The changes someone made
>>>>>>> remote

Usually a conflict arises when you change a part of a file and someone else changes the same part resulting in two different changes for the same part. Git can't resolve such conflict and passes control over to you representing the conflict in a way similar to this example. Now it would be helpful if you know what the text was before any edits, so you can compare your changes to the changes that you are merging with. You can do so by enabling the diff3 as you did

<<<<<<< HEAD
The changes you made
|||||||
The original text
=======
The changes someone made
>>>>>>> remote

Now you are able to see what the ancestor node (the original state) had and compare the 3 states.

PS. usually you would want to do some research before asking here because normally you would be answered by either "check the manual" or "do your research first"

Upvotes: 2

Related Questions