Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the reason for the /a /b prefixes of git diff

Tags:

git

git-diff

I've been using Git for some years now and always wondered why git diff prefixes the names of modified files with a/ and b/. I expected to eventually stumble upon a use-case where it is useful, but until now it was always annoying and never helpful.

What is it good for? Why is this enabled by default? In which situations is it useful?

like image 279
mkl Avatar asked Jul 20 '11 16:07

mkl


People also ask

What does git diff mean?

Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

How does git determine diff?

4 Diff Comparisons You Need to Know You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.

What does git diff head do?

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.

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.


2 Answers

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.

--src-prefix=<prefix> 

Show the given source prefix instead of "a/".

--dst-prefix=<prefix> 

Show the given destination prefix instead of "b/"

like image 107
VonC Avatar answered Sep 26 '22 03:09

VonC


If you don't find it useful, you can turn it off with:

git config --global diff.noprefix true 
like image 31
Will Sheppard Avatar answered Sep 23 '22 03:09

Will Sheppard