git 如何以相反的顺序git log?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2798822/
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
How to git log in reverse order?
提问by Erik B
I recently learned that I can get hg log to print the history in reverse order with:
我最近了解到我可以使用 hg log 以相反的顺序打印历史记录:
hg log -r :
So of course I tried:
所以我当然试过:
git log -r :
Well, it didn't work. So what is the command to do the same thing in git?
好吧,它没有用。那么在 git 中执行相同操作的命令是什么?
回答by Makis
Use the --reverse
option:
使用--reverse
选项:
git log --reverse
回答by Chev
You don't need to type --reverse
all the time, nor do you need a bash function. You can just create a git alias. Open up your favorite text editor and open up your global .gitconfig
file. It's usually found in your home directory.
您不需要一直输入--reverse
,也不需要 bash 函数。您可以只创建一个 git 别名。打开您最喜欢的文本编辑器并打开您的全局.gitconfig
文件。它通常位于您的主目录中。
Navigate to or create a section like this:
导航到或创建一个像这样的部分:
[alias]
lg = log -10 --reverse
That creates a git alias that grabs the ten most recent commits thenreverses that list so the most recent of those 10 is at the bottom. Now you can simply run:
这将创建一个 git 别名,用于获取 10 个最近的提交,然后反转该列表,因此这 10 个中最近的一个位于底部。现在你可以简单地运行:
git lg
git lg
回答by VonC
Jakub Nar?bski's comment("Note that e.g. git log -10 --reverse
would get 10 last commits thenreverse list") has been clarified in Git 2.11 (Q4 2016):
Jakub Nar?bski的评论(“请注意,例如git log -10 --reverse
将获得 10 个最后提交然后反向列表”)已在 Git 2.11(2016 年第四季度)中得到澄清:
See commit 04be694(27 Sep 2016) by Pranit Bauva (pranitbauva1997
).
(Merged by Junio C Hamano -- gitster
--in commit 54a9f14, 11 Oct 2016)
请参阅Pranit Bauva ( ) 的提交 04be694(2016 年 9 月 27 日)。(由Junio C Hamano合并-- --在commit 54a9f14,2016 年 10 月 11 日)pranitbauva1997
gitster
rev-list-options
: clarify the usage of--reverse
Users often wonder if the oldest or the newest
n
commits are shown bylog -n --reverse
.
Clarify that--reverse
kicks in only afterdeciding which commits are to be shown to unconfuse them.
rev-list-options
: 说明用法--reverse
用户经常想知道最旧的
n
提交还是最新的提交是由log -n --reverse
.
澄清--reverse
只有在决定显示哪些提交以消除混淆之后才会启动。
See Commit Limiting.
请参阅提交限制。
回答by wojcieh
I combined few of suggested one into one and I created an alias.
我将几个建议的合二为一,并创建了一个别名。
git log -10 --pretty=oneline --abbrev-commit --reverse
alias gl='git log -10 --pretty=oneline --abbrev-commit --reverse'
回答by Adil Khan
You could create a bashrc function (assuming you are on a unixy os)
您可以创建一个 bashrc 函数(假设您使用的是 unixy 操作系统)
function git_logr {
git log --reverse
}