git diff
git show
git diff <other_branch>
git diff <file_relative_path>
git diff branch1 branch2 file
git diff --name-only
When you run the command git diff branch1 branch2 file
. important parts of the output:
-
File Header:
diff --git a/file b/file
This line indicates that the comparison is being made between the two versions of
file
in the two branches.a/file
represents the file inbranch1
, andb/file
represents the file inbranch2
. -
File Path:
--- a/file +++ b/file
These lines indicate the file paths in the respective branches.
--- a/file
corresponds tobranch1
and+++ b/file
corresponds tobranch2
. -
Change Hunk Headers:
@@ -1,5 +1,6 @@
This line shows the range of lines that are being changed. The
-1,5
indicates that the changes start at line 1 and span 5 lines inbranch1
, and the+1,6
indicates that the changes start at line 1 and span 6 lines inbranch2
. -
Actual Changes:
-line in branch1 that is being removed +line in branch2 that is being added
Lines starting with
-
are present inbranch1
but not inbranch2
. Lines starting with+
are present inbranch2
but not inbranch1
. Lines without any prefix are unchanged and provide context.Example:
-print("Hello from branch1") +print("Hello from branch2")