Git, see a list of comments of my last N commits
GitGit CommitGit Problem Overview
Is there a way to see a list of comments and time of my last N commits in Git?
After looking on SO, the only relevant thing I have found is https://stackoverflow.com/questions/1314950/git-get-all-commits-and-blobs-they-created, but it shows all commits from all users, and outputs a lot of other information.
Git Solutions
Solution 1 - Git
If you want to use the command line you can use the --author=<your name>
For example: to see your last 5 commits
git log -n 5 --author=Salvador
If you want a simpler one line solution:
git log --oneline -n 5 --author=Salvador
Edited to add
If you like the single line version, try creating an alias for git log
like this (this is what I have for 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"
Now, I can just use:
glog -n 5
And I get a nice output such as:
Which is colourised, shows the name of the author and also shows the graph and you can still pass in other flags (such as --author) which lets you filter it even more.
Solution 2 - Git
Use the --author
and/or --committer
filtering options with git log
, plus the -n
option to limit the number of commits. For example:
git log --author='Salvador Dali' -n 10
Solution 3 - Git
git log --format="%h %B" --oneline -n 1
This will get you latest git log comment block with abbreviated commit id.
git log --format="%H %B" -n 1
This will get you latest git log comment block with full commit id.
You can build your own format from : Git Pretty Format
Solution 4 - Git
git log --author="My name" -n 5
(see man git-log
for all alternatives)
Solution 5 - Git
See a list of comments of last N commits
git log --oneline -10
Check out to an older commit
git ckeckout 3e6bb80
Get back to the latest commit after checking out a previous commit
git checkout -
Solution 6 - Git
If you are after only the last X git commit messages, the following command will give you the last 5 commit messages as strings separated by new lines:
git log -5 --oneline --format=%s | sed 's/^.*: //'
will output something like this:
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
Solution 7 - Git
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
Notice ...yellow)%<(113,trunc) the 113 is the length to trim the comments to allowing full customization without --oneline overriding your settings.
As has been said this could be aliased or as I have wrapped in a powershell function.
The following is beyond the OP but brings some value to the thread.
I know I got carried away but it is what we do.
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
}