I have commit number. I would like to get previous commit number(parent). I need commits from current branch.
You can use git rev-parse
for this.
# Output hash of the first parent
git rev-parse $commit^
# Nth parent
git rev-parse $commit^N
# All parents
git rev-parse $commit^@
These constructs are explained in git help rev-parse
:
^, e.g. HEAD^, v1.5.1^0
A suffix ^ to a revision parameter means the first
parent of that commit object. ^ means the th
parent (i.e. ^ is equivalent to ^1). As a
special rule, ^0 means the commit itself and is
used when is the object name of a tag object that
refers to a commit object.
...
^@, e.g. HEAD^@
A suffix ^ followed by an at sign is the same as listing
all parents of (meaning, include anything
reachable from its parents, but not the commit itself).