Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpreting git diff output [duplicate]

Tags:

git

diff

I been using git for years but never used diff command and I started to use it today but I really don't understand the output... I had a file and I removed line 3 and 4 and I got the following output but can someone help me understand what the lines of the output means in dummy terms. thanks

$ git diff
diff --git a/README.txt b/README.txt
index 15827f4..8115e72 100644
--- a/README.txt
+++ b/README.txt
@@ -1,4 +1,2 @@
 this file
 adding like
-line 3
-
like image 291
JMS Avatar asked Jan 10 '23 06:01

JMS


1 Answers

Line 1: The command used to produce the diff.

Line 2: git database information for the two files involved.

Line 3 and 4: --- means old file, +++ means new file.

Line 5: @@ means the range of lines represented in the next diff hunk. -1,4 means lines 1-4 from the old file, and +1,2 means lines 1-2 in the new file.

The remaining lines are lines from the original files, prefixed with either (a space), - or +. lines are in both old and new, - are only in old and + are only in new.

These are meant to be mnemonic: - are "removed lines", are "unchanged lines", and + are "added lines".

like image 143
nneonneo Avatar answered Jan 17 '23 17:01

nneonneo