有没有一种方法可以在Git中查看我最近N次提交的评论和时间列表?
在Stack Overflow上查找后,我只找到了一个相关的东西:Git - get all commits and blobs they created,但它显示所有用户的所有提交,并输出大量其他信息。
有没有一种方法可以在Git中查看我最近N次提交的评论和时间列表?
在Stack Overflow上查找后,我只找到了一个相关的东西:Git - get all commits and blobs they created,但它显示所有用户的所有提交,并输出大量其他信息。
如果你想使用命令行,可以使用 --author=<你的名字>
例如:要查看你最近的5个提交记录
git log -n 5 --author=Salvador
如果你想要更简单的一行代码解决方案:
git log --oneline -n 5 --author=Salvador
编辑后添加
如果你喜欢单行版本,可以尝试创建一个别名来代替 git log
,例如(这是我用于zsh的):
alias glog="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
现在,我只需要使用:
glog -n 5
然后我可以得到一个很好的输出结果,如下图所示:
它被着色,显示了作者的名称并显示了图形,您仍然可以传入其他标志(例如--author),从而使过滤更加精确。
使用git log
命令的--author
和/或--committer
过滤选项,以及-n
选项来限制提交的数量。例如:
git log --author='Salvador Dali' -n 10
git log --format="%h %B" --oneline -n 1
git log --format="%H %B" -n 1
git log --author="我的名字" -n 5
(查看所有替代方法,请参阅man git-log
)
git log -5 --oneline --format=%s | sed 's/^.*: //'
Remove references to Node 8
Move ESLint cache file into node_modules
Update postcss packages
Add TypeScript 4.x as peerDependency to react-scripts
Create FUNDING.yml
git log --oneline -10
检出到较旧的提交
git ckeckout 3e6bb80
在切换到之前的提交后返回最新提交
git checkout -
git log --max-count=15 --pretty="format:%C(dim green) %<(9,trunc)%ar %C(bold magenta)%h %C(bold green)%<(12,trunc)%an %C(bold yellow)%<(113,trunc)%s" --no-merges
请注意...yellow)%<(113,trunc),其中的113是要将注释修剪到的长度,允许完全自定义而不会被--oneline覆盖您的设置。
正如已经说过的,这可以被别名化,或者像我一样封装在powershell函数中。
以下内容超出了OP的范围,但为该线程带来了一些价值。
我知道我有些过分了,但这就是我们所做的。
function logs() {
<#
.SYNOPSIS
Shows my logs
.DESCRIPTION
Returns an abreviated list of logs meeting the filtering provided including max returned, committor by case sensitive pattern, branch, local or remote, and a 'my' shourcut to get the callers commits only
.EXAMPLE
PS>logs
[ Basic usage gets maximum 15 logs from the origin/<current branch> ]
origin/master logs
git log origin/master --max-count=15 --pretty="format:%C(dim green) %<(9,trunc)%ar %C(bold magenta)%h %C(bold green)%<(12,trunc)%an %C(bold yellow)%<(113,trunc)%s"
2 days .. b6e4d0b Joe Johnston Added Posh
2 days .. 0f1a166 Joe Johnston Updated the profile system
4 days .. dfd3115 Joe Johnston added .net install and pinned applications. Updated git functions
6 weeks.. 47bd9e9 Joe Johnston updated functions
3 month.. 5148f09 Joe Johnston initial add
.EXAMPLE
PS>logs -l
[ Usage gets maximum 15 local logs from the <current branch> ]
logs
git log --max-count=15 --pretty="format:%C(dim green) %<(9,trunc)%ar %C(bold magenta)%h %C(bold green)%<(12,trunc)%an %C(bold yellow)%<(113,trunc)%s"
3 hours.. efb36e9 Joe Johnston updated profile to set-execution
3 hours.. 4355a00 Joe Johnston Merge branch 'master' of https://github.com/xxx
3 hours.. 84cd380 Joe Johnston updated gitfunctions - added undomerge
2 days .. b6e4d0b Joe Johnston Added Posh
2 days .. 0f1a166 Joe Johnston Updated the profile system
4 days .. dfd3115 Joe Johnston added .net install and pinned applications. Updated git functions
6 weeks.. 47bd9e9 Joe Johnston updated functions
3 month.. 5148f09 Joe Johnston initial add
.EXAMPLE
logs 25
[ Usage gets maximum 25 logs from the origin/<current branch> ]
.EXAMPLE
logs -m -c 20
[ Usage gets maximum 20 local logs from the <current branch> commited by me]
.EXAMPLE
logs -b dev/iOS -c 25 -l -c "Jackson"
[ Usage gets maximum 20 local logs from the <current branch> commited by the <pattern> Jackson]
#>
[cmdletbinding()]
Param(
[parameter(Mandatory=$false,ValueFromPipeline)]
[Alias('c')]
[int]$Count = 15,
[parameter(Mandatory=$false,ValueFromPipeline)]
[Alias('b')]
[string]$Branch = "Current",
[parameter(Mandatory=$false,ValueFromPipeline)]
[Alias('u')]
[Alias('user')]
[string]$Committer = "",
[parameter(Mandatory=$false,ValueFromPipeline)]
[Alias('m')]
[Alias('me')]
[Alias('onlyme')]
[switch]$My = $false,
[parameter(Mandatory=$false,ValueFromPipeline)]
[Alias('g')]
[switch]$Graph = $false,
[parameter(Mandatory=$false,ValueFromPipeline)]
[Alias('sm')]
[Alias('merge')]
[switch]$ShowMerges = $false,
[parameter(Mandatory=$false,ValueFromPipeline)]
[Alias('r')]
[switch]$Remote = $false
)
$merge = '--no-merges';
if ($ShowMerges) {
$merge = '';
}
$Pretty = "--pretty=`"format:%C(dim green) %<(9,trunc)%ar %C(bold magenta)%h %C(bold green)%<(12,trunc)%an %C(bold yellow)%<(113,trunc)%s`"";
#git config --global format.pretty $Pretty
if ($Branch -eq "Current") {
$Branch = git symbolic-ref --short HEAD;
write-host "************************************************";
} else {
write-host "================================================";
}
if ($Remote -eq $true) { $Where = "origin/$Branch"; }
if ($Graph -eq $true) { $GraphTag = "--graph"; }
if([string]::IsNullOrEmpty($Committer) -eq $false) {
$Who = $Committer;
$Committer = "--committer=" + $Committer;
write-host $Who
}
if ($My -eq $true) {
$me = git config user.name;
$Committer = "--committer=`"$me`"";
$Who = "**MY**";
}
write-host "$Who $Where logs" -foregroundcolor "Red";
$commandOut = "git log $Where $GraphTag --max-count=$Count $Pretty $Committer $GraphTag $merge";
write-Verbose $commandOut;
write-host;
git log $Where --max-count=$Count $Pretty $Committer $GraphTag $merge
write-host
}
像 less
一样工作,具有漂亮的格式,并且没有提示要继续:
git --no-pager log --decorate=short --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' -n5
运行得非常好
git log -5
。如果你正在一个脚本中限制输出的提交数量,应该友善地使用长选项,例如git log --max-count=5
。 - Dennisgit show -n 5
命令来查看最近 5 次提交的更改。 - Black--after="2022-12-1
等结合使用。 - Sentry.co