log first 10 in git

后端 未结 9 1969
刺人心
刺人心 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:46

    Because... more detail :p

    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 third)

    By (no branch), you might be asking about the reflog rather than any given ancestry chain. The following has nothing to do with the branch you are on.

    git log -g --pretty=oneline | tail -10

     HEAD@{###}: action: summary (old)
     HEAD@{###}: action: summary (older)
    ...
     HEAD@{###}: action: summary (oldest)
    
    • -g is --walk-reflogs Instead of walking the commit ancestry chain, walk reflog entries.q
    • add |cut -d ' ' -f 2|tr -d ':' > log to log only the reflog commit index.

    The following will show the earliest ancestors of the currently checked out branch.

    git log --reverse --pretty=oneline | head -10 | cat -n

    1  summary (oldest)
    2  summary (second)
    
    • --reverse Output the commits in reverse order.
    • Can't use simply -n 10 or -10 since it breaks --reverse
    • cat -n adds line numbers (commit index?)

提交回复
热议问题