You can see the differences between two branches in git by using the "git diff
" command, for example, like so:
git diff branch1 branch2
This command will compare the differences between the two branches and display the changes made in "branch2
" (the target branch) as compared to "branch1
" (the source branch). It will show additions, deletions, and modifications to files, along with the corresponding line numbers, producing an output like the following for example:
$ git diff branch1 branch2 diff --git a/README.md b/README.md index 1c5e292..5da8ed7 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ Some content in README.md file. -This line was removed in branch2. +This line was added in branch2. Some content in README.md file.
The output shows the following:
diff --git a/README.md b/README.md
:
— indicates the file being compared (a/file.txt
vs.b/file.txt
).index 1c5e292..5da8ed7 100755
:
— shows the unique identifiers and file mode for the versions being compared.--- a/README.md
:
— indicates the path and name of the source/original version.+++ b/README.md
:
— indicates the path and name of the target/modified version.@@ -1,4 +1,4 @@
:
— hunk header indicating the range of lines in the original and modified versions.Some content in README.md file.
:
— unchanged line in source and target.-This line was removed in branch2.
:
— indicates a line removed in the target version.+This line was added in branch2.
:
— indicates a line added in the target version.Some content in README.md file.
:
— unchanged line in source and target.
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.