miniminimish
miniminimish

Reputation: 97

What exactly does "git diff --base" do?

My notes say the function of git diff --base is to "View the conflicts against the base file (the point where the two branches started diverting the considered file)" but I am not being able to visualize this without any example. How does this differ from the normal git diff command?

Upvotes: 3

Views: 871

Answers (1)

j6t
j6t

Reputation: 13377

Using git diff --base makes sense only for files that are in a conflicted state, for example, during a merge, or a cherry-pick, or a rebase.

When there is a conflict in file foo, there are three versions recorded in the index: the "base" version, "their" version, and "our" version. The "base" version is indeed the version of the file where the two branches started diverging, as you have written in your notes.

Thus, when you type

git diff --base foo

you see the difference of the current version of foo in the worktree to the base version.

Similarly, you can use

git diff --theirs foo
git diff --ours foo

to see the difference to the other two versions involved in the conflict.

Upvotes: 5

Related Questions