How to get parent of specific commit in Git?

前端 未结 8 1219
别跟我提以往
别跟我提以往 2021-02-02 06:25

I have commit number. I would like to get previous commit number(parent). I need commits from current branch.

8条回答
  •  生来不讨喜
    2021-02-02 06:40

    If you only want the ids of the parents of an input commit with id then run this command:

    git cat-file -p  | awk 'NR > 1 {if(/^parent/){print $2; next}{exit}}'
    

    This will work for normal and shallow clones.

提交回复
热议问题