How can I see the differences between two branches?
git diff branch_1..branch_2
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 branch_1...branch_2
And if you just want to check which files differ, not how the content differs. Use this:
git diff --name-only branch_1...branch_2
There are many different ways to compare branches, and it's depend on the specific use case you need.
Many times you want to compare because something broken and you want to see what has been changes, then fix it, and see again what changed before commiting.
Personally when I want to see the diff what I like to do:
git checkout branch_1 # checkout the oldest branchgit checkout -b compare-branch # create a new branchgit merge --no-commit --squash branch_2 # put files from the new branch in the working foldergit status # see file names that changesgit diff # see the content that changed.
Using this solution you will see the diff, you can also see only the file names using git status
, and the most important part you will be able to execute branch_2
while seeing the diff (branch_2 is on the working tree). If something had broken you can editing the files and fix it. Anytime, you can type again git status
or git diff
to see the diff from the new edit to branch_a
.