log first 10 in git

后端 未结 9 1975
刺人心
刺人心 2021-01-30 12:27

Two questions:

  1. How to show the first 10 commit in git from beginning to end. (no branch)
  2. How the specify the commit index and log it. (show the second or
9条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 12:52

    To get the last 10 commits:

    git log HEAD~10..HEAD
    

    To get them in oldest-to-newest order:

    git log --reverse HEAD~10..HEAD
    

    Note that if there are merges, this may show more than 10 commits; add --first-parent if you only want to traverse through the first parent of each branch.

    For far more detail, see the documentation for git rev-list.


    Edit: You've already gotten a useful answer above to "show commits near the start of history" (again, see the caveats about multiple non-connected commit DAGs in a repo). But you can also do, e.g.:

    git log --no-walk `git rev-list HEAD | tail -n 10`
    

    and:

    git log --no-walk `git rev-list --reverse HEAD | head -n 10`
    

    depending on which order you want the results.

提交回复
热议问题