📅  最后修改于: 2023-12-03 15:30:55.645000             🧑  作者: Mango
As a programmer, it's extremely important to keep track of changes made to software projects. Git is a popular version control system that enables developers to do just that. Git logs are a great way to view and understand the history of a project. In this guide, we'll discuss how to use the git log
command in a Shell-Bash environment.
The git log
command is used to view the commit history of a Git repository. By default, it shows the commit ID, author, date, and commit message for each commit in reverse chronological order (newest commit first).
Here's an example:
git log
This will show the commit history for the current branch.
To filter the log output, you can use various options with the git log
command.
For example, to limit the output to the last three commits, you can use the -n
or --max-count
option:
git log -n 3
This will show the last three commits.
To filter the output by author, you can use the --author
option:
git log --author "John Doe"
This will show the commit history for all commits made by "John Doe".
You can also format the log output using placeholders. For example, to show only the commit message and author for each commit, you can use the --format
option:
git log --format="%s - %an"
This will show the commit message and author for each commit.
To view the changes made in a specific commit, you can use the git show
command. For example, to view the diff for the latest commit, you can use:
git show
To view the diff for a specific commit, you can specify the commit hash:
git show 8a17476
This will show the diff for the commit with hash "8a17476".
In conclusion, the git log
command is a powerful tool for viewing and understanding the history of a Git repository. With its many filtering and formatting options, it's easy to find the information you need. We hope this guide has been a helpful introduction to using git log
in a Shell-Bash environment.