155

有没有办法查看我在 Git 中最后 N 次提交的评论列表和时间?

在查看 SO 之后,我发现唯一相关的是 Git - 获取他们创建的所有提交和 blob,但它显示了所有用户的所有提交,并输出了许多其他信息。

4

7 回答 7

255

如果你想使用命令行,你可以使用--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),这可以让您对其进行更多过滤。

于 2012-11-24T14:50:34.703 回答
12

使用--author和/或--committer过滤选项git log,加上-n限制提交次数的选项。例如:

git log --author='Salvador Dali' -n 10
于 2012-11-24T14:47:17.877 回答
6
git log --format="%h %B" --oneline -n 1

这将为您提供带有缩写提交 ID 的最新 git log 注释块。

git log --format="%H %B" -n 1

这将为您提供具有完整提交 ID 的最新 git log 注释块。

您可以通过以下方式构建自己的格式:Git Pretty Format

于 2016-05-02T10:48:57.697 回答
4

git log --author="My name" -n 5(请参阅man git-log所有替代方案)

于 2012-11-24T14:49:04.123 回答
2

查看最后 N 次提交的评论列表

git log --oneline -10

签出一个较旧的提交

git ckeckout 3e6bb80

签出前一个提交后返回最新提交

git checkout -
于 2020-12-12T09:29:15.737 回答
1

如果您只关注最后 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
于 2020-12-31T22:49:01.840 回答
0

git log --max-count=15 --pretty="format:%C(dim green) %<(9,trunc)%ar %C(bold magenta)%h %C(bold green)%<(12, trunc)%an %C(粗黄色)%<(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 
}
于 2021-10-08T19:02:28.203 回答