log first 10 in git

2020-05-14 06:53发布

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

I know that git use parent to link the commit, it's easy to log the commit from end to start. like: git log HEAD~10

But i need to query from the start to end, is it possible?

标签: git logging
9条回答
手持菜刀,她持情操
2楼-- · 2020-05-14 07:17

i would use below simple syntax command;

git log -10 --oneline
查看更多
混吃等死
3楼-- · 2020-05-14 07:23

Simply log everything reverse -1 means list one log

git log  --reverse -1
查看更多
唯我独甜
4楼-- · 2020-05-14 07:24

the best result comes with combination of both best answers:

git log --pretty=oneline -10
查看更多
仙女界的扛把子
5楼-- · 2020-05-14 07:25

In case someone wants more than just git one-line log:

git log --reverse | awk 'NR>1 {print last} {last=$0}; /^commit/ && ++c==11{exit}'

where the 11 at the end should be set to 1 more than the number of commits you want.

As here points out git log --reverse -n 10 doesn't work as you need it to. (I suppose it would need to be non-commutative to give you the ability to chose the first 10 commits in reverse order or the last 10 commits

查看更多
欢心
6楼-- · 2020-05-14 07:26

Simply log everything with one line format and tail the output:

git log  --pretty=oneline | tail -n 10 
查看更多
\"骚年 ilove
7楼-- · 2020-05-14 07:28
git log -10

Would show 10 latest commits matching the revision spec (a missing spec means "all commits").

See manpage:

git help log

section Commit Limiting

-<number>, -n <number>, --max-count=<number>
    Limit the number of commits to output.
查看更多
登录 后发表回答