log first 10 in git
GitLoggingGit Problem Overview
Two questions:
- How to show the first 10 commit in git from beginning to end. (no branch)
- How the specify the commit index and log it. (show the second or third)
I know that git use parent to link the commit, it's easy to log the commit from end to start.
like: git log HEAD~10
But i need to query from the start to end, is it possible?
Git Solutions
Solution 1 - Git
git log -10
Would show 10 latest commits matching the revision spec (a missing spec means "all commits").
See manpage:
git help log
section Commit Limiting
-<number>, -n <number>, --max-count=<number>
Limit the number of commits to output.
Solution 2 - Git
Simply log everything with one line format and tail the output:
git log --pretty=oneline | tail -n 10
Solution 3 - Git
Here my approach,
To get first 10 commits:
git log -n 10
-n is number
Additional To get next 10 commit skip first 10 :
git log --skip=10 -n 10
Solution 4 - Git
To get the last 10 commits:
git log HEAD~10..HEAD
To get them in oldest-to-newest order:
git log --reverse HEAD~10..HEAD
Note that if there are merges, this may show more than 10 commits; add --first-parent
if you only want to traverse through the first parent of each branch.
For far more detail, see the documentation for git rev-list
.
Edit: You've already gotten a useful answer above to "show commits near the start of history" (again, see the caveats about multiple non-connected commit DAGs in a repo). But you can also do, e.g.:
git log --no-walk `git rev-list HEAD | tail -n 10`
and:
git log --no-walk `git rev-list --reverse HEAD | head -n 10`
depending on which order you want the results.
Solution 5 - Git
i would use below simple syntax command;
git log -10 --oneline
Solution 6 - Git
the best result comes with combination of both best answers:
git log --pretty=oneline -10
Solution 7 - Git
Simply log everything reverse -1 means list one log
git log --reverse -1
Solution 8 - Git
Try this neat output format:
git log --date=short -10 --pretty="%C(Yellow)%h %x09 %C(reset)%ad %x09 %C(Cyan)%an: %C(reset)%s"
Solution 9 - Git
Because... more detail :p
- How to show the first 10 commit in git from beginning to end. (no branch)
- How the specify the commit index and log it. (show the second or third)
By (no branch), you might be asking about the reflog
rather than any given ancestry chain. The following has nothing to do with the branch you are on.
git log -g --pretty=oneline | tail -10
<sha> HEAD@{###}: action: summary (old)
<sha> HEAD@{###}: action: summary (older)
...
<sha> HEAD@{###}: action: summary (oldest)
-g
is--walk-reflogs
Instead of walking the commit ancestry chain, walk reflog entries.q- add
|cut -d ' ' -f 2|tr -d ':' > log
to log only the reflog commit index.
The following will show the earliest ancestors of the currently checked out branch.
git log --reverse --pretty=oneline | head -10 | cat -n
1 <sha> summary (oldest)
2 <sha> summary (second)
--reverse
Output the commits in reverse order.- Can't use simply
-n 10
or-10
since it breaks--reverse
cat -n
adds line numbers (commit index?)
Solution 10 - Git
In case someone wants more than just git one-line log:
git log --reverse | awk 'NR>1 {print last} {last=$0}; /^commit/ && ++c==11{exit}'
where the 11
at the end should be set to 1
more than the number of commits you want.
As here points out git log --reverse -n 10
doesn't work as you need it to. (I suppose it would need to be non-commutative to give you the ability to chose the first 10 commits in reverse order or the last 10 commits 浪)