In Git, “git log” is a command that allows you to view the history of commits in a repository. It displays a list of commits, starting from the most recent one and going back in chronological order.
When you run the “git log” command in your terminal or command prompt within a Git repository, you’ll see a detailed output that provides information about each commit. The information typically includes:
- Commit Hash: A unique identifier for each commit. It’s a long string of characters that helps you reference the commit in various Git operations.
- Author and Date: The name and email address of the person who made the commit, along with the date and time the commit was created.
- Commit Message: A short description provided by the author that summarizes the changes made in the commit. This message helps you understand the purpose of the commit.
By default, “git log” displays the commit history in a text-based format, but you can also customize the output using various command-line options. For example, you can specify the number of commits to show, filter the commits based on specific criteria, or format the output to include additional information.
The commit history displayed by “git log” is essential for understanding the evolution of a Git repository. It helps you track changes, identify who made specific modifications, and review the progression of the project over time. Additionally, the commit hash provided in the log allows you to reference specific commits when performing operations like reverting changes, creating branches, or merging code.
git log Command Examples
1. Show the sequence of commits starting from the current one, in reverse chronological order of the Git repository in the current working directory:
# git log
2. Show the history of a particular file or directory, including differences:
# git log -p /path/to/file_or_directory
3. Show an overview of which file(s) changed in each commit:
# git log --stat
4. Show a graph of commits in the current branch using only the first line of each commit message:
# git log --oneline --graph
5. Show a graph of all commits, tags and branches in the entire repo:
# git log --oneline --decorate --all --graph
6. Show only commits whose messages include a given string (case-insensitively):
# git log -i --grep search_string
7. Show the last N commits from a certain author:
# git log -n number --author=author
8. Show commits between two dates (yyyy-mm-dd):
# git log --before="2017-01-29" --after="2017-01-17"
Overall, “git log” is a powerful command that provides a detailed view of the commit history in a Git repository, enabling you to navigate and analyze the changes made to the project.