Do not use git-log for scripting: use either git-rev-list
, or git-log
with specified custom format (--format=*<sth>*
option).
There is additional problem with your question: there can exist more than one such TAIL root commit (parentless commit) in a repository (even if we discount disconnected branches, such as 'html', 'man' and 'todo' in git.git repository). This is usually result of joining separate projects in one, or using subtree merge of separately developed subproject.
For example git repository has 6 root commits: git-gui, gitk (subtree-merged), gitweb (merged in, no longer developed separately), git mail tools (merged very early in project history), and p4-fast-export (perhaps accidental). That is not counting roots of 'html and 'man' branches, "convenience" branches which contains pre-generated documentation, and 'todo' branch with TODO list and scripts.
If you have git 1.7.4.2 or newer, you can use the --max-parents
option:
$ git rev-list --max-parents=0 HEAD
Otherwise, you can get list of all parentless (root) commits accessible from current branch using:
$ git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$"
Solution
git checkout master
git merge C
With C
being the SHA1 of commit C
.
Result
D (dev)
/
master A - B - C (move master HEAD)
It should be a fast-forward merge.
Best Answer
What you're looking for is the command
merge-base
:will print the best common ancestor of those two branches, i.e. where they forked apart. (The documentation has pretty pretty pictures to clarify some of the interesting cases)
An additional tidbit is you can add the
merge-base
flag--fork-point
to automatically include the namefeature-branch
, read more in this answer.