JY2k JY2k - 3 months ago 11
Git Question

Git - Is a commit A before or after B

I want to be able to understand between which 2 tags (tags which represent versions of my app) a commit is.

Is there a command for discerning if Commit A is a parent higher up the tree of commit B.

Answer

Regarding tags

You can at least know if your commit is done after a tag with git describe:

 git describe --tags
 aTagName-n-gxxxx

aTagName represents the closest tag from your current commit.
If your commit is past that tag, you won't get just its name, but aTagName-n-gxxxx, with n being the number of commits after that tag to your current commit, represented by the SHA1 xxx.

You can combine that with git tag --contains <yourCommit> in order to get the tags which includes your commit: the last one should be the oldest one whose history still include your commit.

Regarding commits:

Is there a command for discerning if Commit A is a parent higher up the tree of commit B.

See "How can I tell if one commit is an ancestor of another commit (or vice-versa)?"

git merge-base --is-ancestor <commit1> <commit2>