I have two branches: branch_1
and branch_2
.
How can I see the differences between them?
On the Github, go to the Source view of your project. You will see a link named 'Branch List'. Once the page opens you can see a list of all the remote branches. Hit on the Compare button in front of any of the available branches to see the difference between two branches.
To add some details on usage, the way I found to compare branches in Git Lens is to; Open the Explorer view (Ctrl + Shift + E), find the Git Lens group, right click the branch you want to compare and select 'Select for Compare',then right click the second branch and select 'Compare with Selected'.
The diff can be done with git diff (followed by the filename or nothing if you want to see the diff of all modified files). But if you already did something like git add * , you have to undo with git restore --staged .
You want to use git diff.
git diff [<options>] <commit>..<commit> [--] [<path>…]
Where <commit>
is your branch name, the hash of a commit or a shorthand symbolic reference
For instance git diff abc123..def567
or git diff HEAD..origin/master
That will produce the diff between the tips of the two branches. If you'd prefer to find the diff from their common ancestor to test, you can use three dots instead of two:
git diff <commit>...<commit>
And if you just want to check which files differ, not how the content differs, use --name-only
:
git diff --name-only <commit>..<commit>
Note that in the <commit>..<commit>
(two dot) syntax, the dots are optional; the following is synonymous:
git diff commit1 commit2
It's very simple. You just go to one branch (e.g. main
is your branch).
Run the command
git checkout main git diff branch2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With