How to get parent of specific commit in Git?

前端 未结 8 1246
别跟我提以往
别跟我提以往 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 trying to get all parents and using revision parameter syntax, you may try using log subcommand with --no-walk option.

    An example, if we have the following:

    $ git --oneline --graph
    *   A
    |\
    | * B
    | * C
    | * D
    * |   E
    

    In this example, I'll use ^@ to get all parents and the --no-walk option to show only the parents and not their ancestors.

    $ git log --no-walk A^@
    commit B
        ........
    
    commit E
        ........
    

    Check out git rev-parse for more detail about revision parameter.

提交回复
热议问题