Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do two plus signs in a git diff mean?

Tags:

I am doing a git diff and for the first time, I am seeing double plus-signs next to lines.

++        if ($field_name == $selected) {
++
++        echo "field_type: {$field['type']}\n";
++        echo "field_name: {$field_name}\n";
++
++        foreach ( $node->$field_name as $language => $value ) {

What does it mean? I googled it, and this result doesn't really explain it. I looked at man and the one example I found doesn't seem to explain it either:

3. It is followed by two-line from-file/to-file header

               --- a/file
               +++ b/file

           Similar to two-line header for traditional unified diff format, /dev/null is used to signal created or deleted files.

What does it mean? I've made changes to the file that are greater than 50% of the previous version. Does it have to do with a file re-write? That's what happened when I committed it.

like image 693
user151841 Avatar asked Apr 21 '15 14:04

user151841


People also ask

What is plus/minus in git?

It supposed to reflect the number of changes (in lines) to each file listed. Plus signs for additions, minuses for deletions.

What do the numbers in git diff mean?

- means "old", as we usually invoke it as diff -u old new . +1,4 means that this piece of the second file starts at line 1 and shows a total of 4 lines. Therefore it shows lines 1 to 4. + means "new". We only have 4 lines instead of 6 because 2 lines were removed!

How do you tell the difference in files in git?

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 M mean in git diff?

^M represents carriage return. This diff means something removed a Unicode BOM from the beginning of the line and added a CR at the end.


1 Answers

These lines are added since the last version.

From the manual page:

- static void describe(char *arg)
 -static void describe(struct commit *cmit, int last_one)
++static void describe(char *arg, int last_one)

In the above example output, the function signature was changed from both files (hence two - removals from both file1 and file2, plus ++ to mean one line that was added does not appear in either file1 nor file2). Also eight other lines are the same from file1 but do not appear in file2 (hence prefixed with {plus}).

See diff manual:

https://www.kernel.org/pub/software/scm/git/docs/v1.7.3/git-diff.html

like image 50
Zelldon Avatar answered Sep 23 '22 15:09

Zelldon