How to find the most recent common ancestor of two Git branches?
DESCRIPTION. git merge-base finds best common ancestor(s) between two commits to use in a three-way merge. One common ancestor is better than another common ancestor if the latter is an ancestor of the former. A common ancestor that does not have any better common ancestor is a best common ancestor, i.e. a merge base.
Git Merge Vs Git Rebase:Git merge is a command that allows you to merge branches from Git. Git rebase is a command that allows developers to integrate changes from one branch to another. In Git Merge logs will be showing the complete history of the merging of commits.
git diff master...feature
shows all the new commits of your current (possibly multi-commit) feature branch.
man git-diff
documents that:
git diff A...B
is the same as:
git diff $(git merge-base A B) B
but the ...
is easier to type and remember.
As mentioned by Dave, the special case of HEAD
can be omitted. So:
git diff master...HEAD
is the same as:
git diff master...
which is enough if the current branch is feature
.
Finally, remember that order matters! Doing git diff feature...master
will show changes that are on master
not on feature
.
I wish more git commands would support that syntax, but I don't think they do. And some even have different semantics for ...
: What are the differences between double-dot ".." and triple-dot "..." in Git commit ranges?
You are looking for git merge-base
. Usage:
$ git merge-base branch2 branch3 050dc022f3a65bdc78d97e2b1ac9b595a924c3f2
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