Git Log
Git's git log
command is a powerful tool for examining the commit history of a
repository.We'll dive into the various ways you can use
git log
to explore the commit history specifically for branches. Understanding
how to navigate and analyze branch-specific history is crucial for gaining insights into the
development timeline and understanding how branches have evolved over time.
1. Viewing the Commit History of a Specific Branch:
To see the commit history of a specific branch, use the following command:
bashgit log branch-name
Replace branch-name
with the name of the branch you're interested in. This
command displays the commit messages, authors, and timestamps for the specified branch.
2. Displaying a Graphical Representation:
Enhance your understanding of branch history by visualizing it as a graph. Use the
--graph
option:
bashgit log --graph --oneline --all
This command shows a compact, one-line representation of commits, branches, and merges.
3. Filtering Commits by Author:
If you want to see only the commits made by a specific author in a branch, use the
--author
option:
bashgit log --author="John Doe" branch-name
Replace "John Doe" with the author's name.
4. Limiting the Number of Commits Displayed:
When dealing with long commit histories, limit the number of displayed commits using the
-n
option:
bashgit log -n 5 branch-name
This shows only the latest 5 commits in the specified branch.
5. Displaying Commit Details:
To view detailed information about each commit, use the --stat
option:
bashgit log --stat branch-name
This includes the files that were modified, added, or deleted in each commit.
6. Showing Commit Differences:
To see the actual changes made in each commit, use the -p
option:
bashgit log -p branch-name
This command displays the full diff for each commit, providing a comprehensive view of the changes made.
7. Time-Based Filtering:
Filter commits based on a specific time range using the --since
and
--until
options:
bashgit log --since="2022-01-01" --until="2022-12-31" branch-name
This helps narrow down the commit history to a particular timeframe.
8. Following Branch History Across Merges:
Include merge commits in the log to see how branches have been integrated:
bashgit log --merges branch-name
This highlights merge commits, giving you insights into the integration points of branches.
9. Displaying Only Merge Commits:
To view only merge commits without individual commits, use the --merges
option:
bashgit log --merges --oneline branch-name
This simplifies the log to focus on merge events.
10. Custom Formatting:
Customize the output format of git log
using the --pretty
option.
For example, display each commit on one line:
bashgit log --pretty=oneline branch-name
Experiment with different formatting options to suit your preferences.