gitk Git Command Guide
The gitk command is The Git repository browser that displays changes in a repository or selected commits, including visualizing the commit graph, showing commit-related information, and browsing files at each revision.
gitk Syntax:
Section titled “gitk Syntax:”gitk [<options>] [<revision-range>] [--] [<path>...]Options:
Section titled “Options:”| Option | Description |
|---|---|
| —all | Show all refs (branches, tags, remotes) |
| —branches[= | Show branches matching pattern |
| —tags[= | Show tags matching pattern |
| —remotes[= | Show remotes matching pattern |
| —since= | Show commits more recent than date |
| —until= | Show commits older than date |
| —author= | Show commits by authors matching pattern |
| —committer= | Show commits by committers matching pattern |
| —grep= | Show commits with messages matching pattern |
| —max-count= | Limit number of commits shown |
| —merges | Show only merge commits |
| —no-merges | Don’t show merge commits |
| —first-parent | Follow only first parent in merges |
| —oneline | Condensed commit display |
Parameters:
Section titled “Parameters:”| Parameter | Description |
|---|---|
| Commits to display (e.g., master..develop) | |
| Restrict to commits touching specified paths |
gitk Command Samples:
Section titled “gitk Command Samples:”Browse complete repository history
Section titled “Browse complete repository history”gitk --allShows all branches, tags, and remotes in the repository history graph.
View specific branch range
Section titled “View specific branch range”gitk master..feature-branchVisualizes commits that exist in feature-branch but not in master.
Show recent commits by author
Section titled “Show recent commits by author”gitk --since="2 weeks ago" --author="John Doe"Displays commits by John Doe made in the last 2 weeks.
Browse commits touching specific file
Section titled “Browse commits touching specific file”gitk -- src/main.cShows history of changes to main.c file only.
View merge commits only
Section titled “View merge commits only”gitk --merges --since="1 month ago"Displays only merge commits from the past month.
Follow only first parent in merges
Section titled “Follow only first parent in merges”gitk --first-parent masterShows linear history along master branch, ignoring merge commits.
Search commit messages
Section titled “Search commit messages”gitk --grep="fix.*memory leak"Finds commits with messages containing “fix” followed by “memory leak”.
View tags and their history
Section titled “View tags and their history”gitk --tagsShows all tagged commits in chronological order.
Limit display count
Section titled “Limit display count”gitk --max-count=50 --allshows the most recent 50 commits across all branches.
View commits by multiple authors
Section titled “View commits by multiple authors”gitk --author="Alice\|Bob" --since="2024-01-01"Displays commits by either Alice or Bob since New Year.
How does gitk visualize the commit graph?
Section titled “How does gitk visualize the commit graph?”gitk renders the commit Directed Acyclic Graph (DAG) as a visual tree where each commit node shows parent relationships. Lines connect children to parents, diverging for branches and converging at merges.
What’s the difference between gitk and git log —graph?
Section titled “What’s the difference between gitk and git log —graph?”While git log --graph shows text-based graph representation in terminal, gitk provides interactive GUI with clickable commits, expandable diffs, and file browsing capabilities.
Can gitk show diffs for binary files?
Section titled “Can gitk show diffs for binary files?”gitk cannot display diffs for binary files directly but can show that a binary file changed and list its basic information. Use git diff command line for detailed binary file analysis.
How do I save gitk views for later?
Section titled “How do I save gitk views for later?”gitk doesn’t have built-in view saving, but you can create shell aliases or scripts that invoke gitk with specific option combinations for recurring analyses.
Does gitk support Git LFS (Large File Storage)?
Section titled “Does gitk support Git LFS (Large File Storage)?”gitk can show LFS file commits and basic information but cannot display actual large file contents. LFS integration shows file status but delegates actual content viewing to external tools.
Can I create commits directly in gitk?
Section titled “Can I create commits directly in gitk?”No, gitk is strictly a repository browser for visualization and exploration. For creating or modifying commits, use git gui or command-line Git tools.
What’s the performance impact of loading large repositories in gitk?
Section titled “What’s the performance impact of loading large repositories in gitk?”gitk loads entire commit history into memory, so performance degrades with large repositories (>10,000 commits). Use --max-count or narrowed revision ranges to improve responsiveness.
How do I customize gitk display colors?
Section titled “How do I customize gitk display colors?”gitk supports limited color customization through X11 resources or command-line options, but color schemes are more limited compared to modern GUI tools.
Can gitk handle repository with multiple remote tracking branches?
Section titled “Can gitk handle repository with multiple remote tracking branches?”Yes, gitk shows all refs including remote-tracking branches. Use —remotes option to focus specifically on remote references, or —all to include everything.
What’s the relationship between gitk and git gui?
Section titled “What’s the relationship between gitk and git gui?”While gitk focuses on history browsing, git gui focuses on authoring commits. However, git gui can launch gitk sessions, and both share Tk interface components.
How does gitk handle encoding issues?
Section titled “How does gitk handle encoding issues?”gitk depends on Tcl/Tk encoding settings and system locale. Encoding problems manifest as corrupted characters in commit messages or file names.
Can I export gitk graphs as images?
Section titled “Can I export gitk graphs as images?”gitk doesn’t provide direct image export, but you can use external tools like git log --graph --oneline | cat and convert to images, or take screenshots of the gitk window.
How do I find specific commits in gitk?
Section titled “How do I find specific commits in gitk?”Use search functionality (Ctrl+F) to find by commit ID, author, or message content. Right-click commits for additional context menu options like copying IDs or marking commits.
Does gitk support submodules?
Section titled “Does gitk support submodules?”gitk shows submodule commits and status but doesn’t provide deep submodule navigation. Each submodule appears as a regular file change in gitk displays.
Can I see file history per line in gitk?
Section titled “Can I see file history per line in gitk?”gitk shows commit-to-commit differences but doesn’t provide line-by-line historical annotation like git blame. For detailed line history, use git gui blame or git blame.
Applications of the gitk command
Section titled “Applications of the gitk command”- Repository Archaeology: Discovering historical changes and understanding code evolution
- Bug Investigation: Tracing when bugs were introduced and by whom
- Code Review Preparation: Visualizing complex merge histories and branch interactions
- Release Analysis: Understanding what changed between releases and version tags
- Educational Exploration: Visual learning of Git branching and merging concepts
- Repository Maintenance: Identifying unusual commit patterns or branch structures