如何在一个Git仓库中找到最新的提交?

30

我有一个 Git 仓库,其中有许多分支和提交记录。我想找到最近的10个提交记录,应该如何操作?谢谢!

4个回答

43

如果你想要所有分支的提交记录,需要使用 --all 参数,使用 -10 限制 git log 只显示最近的十条记录,并且使用 --date-order 告诉 git log 按照日期顺序排序提交记录。

git log -10 --all --date-order

7

获取所有分支的最近10个提交记录,可以执行以下操作:

git log --graph --all --format=format:'%h - (%ai) %s — %cn %d' \ 
  --abbrev-commit --date=relative -10
  • %h 表示提交的哈希值
  • %ai 表示作者提交日期(使用%ci表示提交者提交日期)
  • %s 表示提交主题
  • %cn 表示提交者姓名
  • -10 表示最近的10次提交

如果您需要进一步自定义,请参阅此处获取更多信息: http://linux.die.net/man/1/git-log


4
要查找特定数量的提交,您可以使用-n选项:
git log -5  # or git log -n 5 # fetches the last 5 commits

正如@honk指出的,-n 5-5是等价的。

查找其他分支上的提交,而不必检出其他分支:

git log branch_name

如果你在develop分支上,并希望获取master分支最后的10个提交记录(单行显示),你可以执行以下命令:

git log --oneline master  -10

要查看所有分支的提交,需要使用--all参数。
git log --all

1
你可以写成 -n 5-5 是等价的。而要查看所有分支,当然要使用 -all(谈论 git CLI 的难度)。 - Benjamin Bannier
@honk - 是的。我想你是指 --all。我会更新答案。谢谢。 - prasvin

1
尝试这个git log --graph,你将会得到按照最新到旧的顺序列出的提交记录。
•the checksum of the commit 
•the author name and email 
•the date the author committed it 
•the full commit message

编辑:

或者你可以使用:

git log --pretty=oneline --graph

这会显示所有的提交和分支拓扑结构


我想获取所有分支中的最新提交。 - why

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接