Today I have learned two different usages of git
command. First, to
list the least common ancestor of two refs, we may use following command:
$ git merge-base --octopus <commit_1> <commit_2> ... <commit_n>
Please notice that --octopus
is mandatory; otherwise, git
will create a hypothetical commit M
, which merges commit_2
..
commit_n
, and then compute the common ancestor of commit_1
and
M
.
The git merge-base
command will print the SHA1 of the least common
ancestor. If such commit is not available, then git
will return with
error.
The second usage I have learned is that we can create a orphan branch with following commands:
$ git checkout --orphan <new-branch-name>
$ git reset
$ rm -rf *
... add files ...
$ git commit
The orphan branch will be completely independent of the existing branches. This is helpful when creating GitHub Pages branch.