在 git 中记录前 10 个

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10345182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:34:06  来源:igfitidea点击:

log first 10 in git

gitlogging

提问by yohan zhou

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)
  1. 如何在 git 中从头到尾显示前 10 次提交。(无分行)
  2. 如何指定提交索引并记录它。(显示第二个或第三个)

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

我知道 git 使用 parent 来链接提交,很容易从头到尾记录提交。喜欢:git log HEAD~10

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

但是我需要从头到尾查询,可以吗?

采纳答案by CharlesB

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

只需用一行格式记录所有内容并拖尾输出:

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

回答by kostix

git log -10

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

将显示与修订规范匹配的 10 个最新提交(缺少的规范意味着“所有提交”)。

See manpage:

请参阅联机帮助页:

git help log

section Commit Limiting

部分 Commit Limiting

-<number>, -n <number>, --max-count=<number>
    Limit the number of commits to output.

回答by Nayagam

Here my approach,

这是我的方法,

To get first 10 commits:

要获得前 10 次提交:

git log -n 10

-n is number

-n 是数字

AdditionalTo get next 10 commit skip first 10 :

附加要获得下 10 个提交,请跳过前 10 个:

git log --skip=10 -n 10

回答by torek

To get the last 10 commits:

获取最后 10 次提交:

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-parentif you only want to traverse through the first parent of each branch.

请注意,如果有合并,这可能会显示超过 10 个提交;加--first-parent,如果你只希望通过每个分支的第一个父遍历。

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

有关更多详细信息,请参阅git rev-list.



编辑:您已经在上面获得了“在历史开始附近显示提交”的有用答案(同样,请参阅有关存储库中多个非连接提交 DAG 的警告)。但你也可以这样做,例如:

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.

取决于您想要结果的顺序。

回答by andrej

the best result comes with combination of both best answers:

最好的结果来自两个最佳答案的组合:

git log --pretty=oneline -10

回答by nickleefly

Simply log everything reverse -1 means list one log

简单地记录所有反向 -1 意味着列出一个日志

git log  --reverse -1

回答by here

Because... more detail :p

因为......更多细节: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)
  1. 如何在 git 中从头到尾显示前 10 次提交。(无分行)
  2. 如何指定提交索引并记录它。(显示第二个或第三个)


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

通过(无分支),您可能会询问reflog而不是任何给定的祖先链。以下与您所在的分支无关。

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

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

<sha> HEAD@{###}: action: summary (old)
<sha> HEAD@{###}: action: summary (older)
...
<sha> HEAD@{###}: action: summary (oldest)
  • -gis --walk-reflogsInstead of walking the commit ancestry chain, walk reflog entries.q
  • add |cut -d ' ' -f 2|tr -d ':' > logto log only the reflog commit index.
  • -g--walk-reflogs不是走在提交祖先链,走引用日志entries.q
  • 添加|cut -d ' ' -f 2|tr -d ':' > log以仅记录 reflog 提交索引。


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

下面将显示当前检出分支的最早祖先。

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

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

1 <sha> summary (oldest)
2 <sha> summary (second)
  • --reverseOutput the commits in reverse order.
  • Can't use simply -n 10or -10since it breaks --reverse
  • cat -nadds line numbers (commit index?)
  • --reverse以相反的顺序输出提交。
  • 不能简单地使用-n 10-10因为它坏了--reverse
  • cat -n添加行号(提交索引?)


回答by Cameron Stone

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

如果有人想要的不仅仅是 git 单行日志:

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

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

其中,11在年底应设置为1比你想提交的数目。

As herepoints out git log --reverse -n 10doesn'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)

正如这里指出的那样,git log --reverse -n 10它不能按您的需要工作。(我想它需要是不可交换的,才能让您能够以相反的顺序选择前 10 次提交或最后 10 次提交

回答by RAVI PATEL

i would use below simple syntax command;

我会使用以下简单的语法命令;

##代码##