【发布时间】:2012-11-24 14:36:11
【问题描述】:
有没有办法在 Git 中查看我最后 N 次提交的 cmets 列表和时间?
在查看 SO 之后,我发现唯一相关的事情是 Git - get all commits and blobs they created,但它显示了所有用户的所有提交,并输出了很多其他信息。
【问题讨论】:
标签: git git-commit
有没有办法在 Git 中查看我最后 N 次提交的 cmets 列表和时间?
在查看 SO 之后,我发现唯一相关的事情是 Git - get all commits and blobs they created,但它显示了所有用户的所有提交,并输出了很多其他信息。
【问题讨论】:
标签: git git-commit
如果你想使用命令行可以使用--author=<your name>
例如:查看你最近的 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 -5。如果您要限制脚本中输出的提交次数,您应该善待他人并使用 long 选项,例如git log --max-count=5.
git show -n 5查看最近5次提交的变化
将--author 和/或--committer 过滤选项与git log 结合使用,再加上-n 选项来限制提交次数。例如:
git log --author='Salvador Dali' -n 10
【讨论】:
git log --format="%h %B" --oneline -n 1
这将为您提供最新的 git log 注释块,带有缩写的提交 id。
git log --format="%H %B" -n 1
这将为您提供具有完整提交 ID 的最新 git 日志评论块。
您可以从以下位置构建自己的格式:Git Pretty Format
【讨论】:
git log --author="My name" -n 5(请参阅man git-log 了解所有备选方案)
【讨论】:
查看最近 N 次提交的 cmets 列表
git log --oneline -10
签出一个较旧的提交
git ckeckout 3e6bb80
签出之前的提交后返回到最新的提交
git checkout -
【讨论】:
如果您只关注最后 X 条 git 提交消息,则以下命令会将最后 5 条提交消息作为由新行分隔的字符串提供:
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 --max-count=15 --pretty="format:%C(dim green) %
注意 ...yellow)%
如前所述,这可能是别名,或者我已经包装在一个 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
}
【讨论】: