gitk is a graphical history viewer for Git repositories. It provides a visual representation of the commit history, making it easier to understand the changes made over time.
Table of Contents
- Synopsis
- Description
- Basic Usage
- Common gitk Options and Examples
- Rev-List Options
- Gitk-Specific Options
- Advanced Usage Examples
- Configuration
- Conclusion
Synopsis
gitk [<options>] [<revision-range>] [--] [<path>…]
Description
Displays changes in a repository or a selected set of commits. This includes visualizing the commit graph, showing information related to each commit, and the files in the trees of each revision.
Basic Usage
To start gitk, navigate to your Git repository in the terminal and run:
code2care@mac % gitk
This command opens the gitk interface, displaying the commit history in a graphical format.
Common gitk Options and Examples
| Option | Description | Example |
|---|---|---|
| --all | Show all refs (branches and tags) | |
| --since="date" | Show commits more recent than a specific date | |
| --until="date" | Show commits older than a specific date | |
| --max-count=<n> | Limit the number of commits to display | |
| --branches=<pattern> | Show only branches matching the pattern | |
| --author=<pattern> | Show only commits by authors matching the pattern | |
| --grep=<pattern> | Show only commits with log message matching the pattern | |
| <branch1>..<branch2> | Show the difference between two branches | |
| <path> | Show only commits that affected the specified path | |
Rev-List Options
gitk supports most options applicable to the git rev-list command. Some key options include:
: Sort commits by date when possible.--date-order
: Show the commits on the history between two branches that modify the conflicted files.--merge
: Mark which side of a symmetric difference a commit is reachable from.--left-right
: When filtering history with <path>, does not prune some history.--full-history
: Remove some needless merges from the resulting history.--simplify-merges
: Only display commits that exist directly on the ancestry chain between two commits.--ancestry-path
Gitk-Specific Options
: Command to be run each time gitk has to determine the revision range to show.--argscmd=<command>
: Select the specified commit after loading the graph.--select-commit=<ref>
Advanced Usage Examples
- View commits from the last month, excluding merges:
code2care@mac % gitk --since="1 month ago" --no-merges - Show commits touching a specific file in a date range:
code2care@mac % gitk --since="2023-01-01" --until="2023-06-30" path/to/file.txt - Display commits from all branches containing a specific keyword:
code2care@mac % gitk --all --grep="refactor" - View commits by a specific author on a particular branch:
code2care@mac % gitk --author="Jane Smith" feature-branch - Show the last 20 commits affecting a specific directory:
code2care@mac % gitk -n 20 -- src/ - Show changes since version v2.6.12 in specific directories:
code2care@mac % gitk v2.6.12.. include/scsi drivers/scsi - Show changes during the last two weeks to a specific file:
code2care@mac % gitk --since="2 weeks ago" -- gitk - Show at most 100 changes made to a file in all branches:
code2care@mac % gitk --max-count=100 --all -- Makefile
Configuration
User configuration and preferences are stored at:
if it exists, otherwise$XDG_CONFIG_HOME/git/gitk
if it exists$HOME/.gitk
If neither of the above exist, then
$XDG_CONFIG_HOME/git/gitk is created and used by default. If $XDG_CONFIG_HOME is not set, it defaults to $HOME/.config in all cases.
Conclusion
gitk is a powerful tool for visualizing your Git repository's history. By combining various options and arguments, you can create highly specific views of your project's commit history, making it easier to track changes, debug issues, and understand the evolution of your codebase.
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!