Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does diff.mnemonicprefix do?

Tags:

git

I've noticed that SourceTree performs git commands with this configuration option:

git -c diff.mnemonicprefix=false  

This is what the git docs say about this option:

diff.mnemonicprefix

If set, git diff uses a prefix pair that is different from the standard "a/" and "b/" depending on what is being compared. When this configuration is in effect, reverse diff output also swaps the order of the prefixes:

git diff compares the (i)ndex and the (w)ork tree;

git diff HEAD compares a (c)ommit and the (w)ork tree;

git diff --cached compares a (c)ommit and the (i)ndex;

git diff HEAD:file1 file2 compares an (o)bject and a (w)ork tree entity;

git diff --no-index a b compares two non-git things (1) and (2).

I still don't understand what this means. Can someone explain?

like image 892
rink.attendant.6 Avatar asked Jan 19 '15 02:01

rink.attendant.6


People also ask

What does the A and B mean in git diff?

As mentioned in the diff man page, a/ and b/ represent the prefix to differentiate source and destination. Actually, you have the options: --no-prefix. Do not show any source or destination prefix.

What is git diff head?

The git diff HEAD [filename] command allows you to compare the file version in your working directory with the file version last committed in your remote repository. The HEAD in the git command refers to the remote repository.


Video Answer


1 Answers

git diff shows some metadata about the files it is comparing. Ordinarily you might see something like this:

diff --git a/foo/bar.txt b/foo/bar.txt        <-- index abcd123..1234abc 100644 --- a/foo/bar.txt                             <-- +++ b/foo/bar.txt                             <-- 

Note how the files are differentiated using a/ and b/ on the three lines I have indicated with arrows. This is non-mnemonic; the characters a and b have no real significance.

With diff.mnemonicprefix enabled, these characters are chosen as described in the documentation you quoted. For example, if you have changes to your local copy and are comparing against the index (e.g. with git diff) you would see something like

diff --git i/foo/bar.txt w/foo/bar.txt index abcd123..1234abc 100644 --- i/foo/bar.txt +++ w/foo/bar.txt 

instead. The characters i and w are used to indicate your index and working copy respectively.

The other cases listed in the documentation work similarly.

like image 83
Chris Avatar answered Sep 28 '22 16:09

Chris