I have one git repository, there are many branches many commits, I want to find the latest 10 commits, how to do this , thanks!
To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.
Git file History provides information about the commit history associated with a file. To use it: Go to your project's Repository > Files. In the upper right corner, select History.
Use the following command to find out how many commits there have been in a git repository. Not really useful in itself, but an interesting figure to see how active a project has been over it's lifetime. --oneline - Removes some of the information from the log entries and displays each on a single line.
git log my/file.c If you really only want to list the one most recent commit, for example to use it in a script, use the -n 1 option: git log -n 1 --pretty=format:%H -- my/file.c --pretty=format:%h tells git log to show only the commit hash.
If you want commits for all branches you need the --all argument, limit git log to ten with -10 and use --date-order to tell git log to sort the commits with respect to date. git log -10 --all --date-order
The commit history can be viewed in different ways by using the ` git log ` command. A local repository named bash has been used in this tutorial to test the commands used in this tutorial. Run the following command to view the commit history of the repository.
If you want commits for all branches you need the --all argument, limit git log to ten with -10 and use --date-order to tell git log to sort the commits with respect to date.
git log -10 --all --date-order
For last 10 commits in all branches, you can do:
git log --graph --all --format=format:'%h - (%ai) %s — %cn %d' --abbrev-commit --date=relative -10
See here for more info if you need to customize further: http://linux.die.net/man/1/git-log
To find specific number of commits you can use the -n
option :
git log -5 # or git log -n 5 # fetches the last 5 commits
As, @honk pointed out, -n 5
and -5
are equivalent.
To find commits on other branch, without checking out the other branch :
git log branch_name
So, if you are at develop branch and wish to get last 10 commits of master(oneline), you could do:
git log --oneline master -10
To view commits of all branches there's a --all
argument.
git log --all
Try this git log --graph
& you will get the commits in the order latest to old along with
•the checksum of the commit
•the author name and email
•the date the author committed it
•the full commit message
EDIT:
or you can use:
git log --pretty=oneline --graph
which gives all the commits & branch topology
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With