How to use the command 'tig' (with examples)
The ’tig’ command is a text-mode interface for Git. It provides a user-friendly way to visualize and navigate the Git repository history, making it easier to understand and work with Git.
Use case 1: Show the sequence of commits starting from the current one in reverse chronological order
Code:
tig
Motivation:
This use case is useful when you want to quickly visualize the commit history of the current branch. It helps you understand the sequence of commits made and their corresponding changes.
Explanation:
The command ’tig’ without any arguments will show the sequence of commits starting from the current one in reverse chronological order. It opens a text-based user interface where you can navigate through the commits using keyboard shortcuts.
Example output:
commit: 05738fc329d3a75d64yx9ah4b10cba4430a0318a
Author: John Doe <john.doe@example.com>
Date: Mon Oct 11 12:34:56 2021 -0400
Update README.md
commit: 6c64a2d9ecc1b4a21ydx0vt628cc97553dd76a23
Author: Jane Smith <jane.smith@example.com>
Date: Fri Oct 08 09:12:34 2021 -0400
Add new feature
commit: a57cda18ae87200431xztsg842e7f9d76b4b12d
Author: John Doe <john.doe@example.com>
Date: Wed Oct 06 15:43:21 2021 -0400
Initial commit
Use case 2: Show the history of a specific branch
Code:
tig branch
Motivation:
This use case is helpful when you want to view the commit history of a specific branch. It allows you to understand the changes and modifications made to the branch over time.
Explanation:
By specifying the branch name as an argument after the ’tig’ command, such as ’tig branch’, you can view the commit history of that particular branch. This command opens the ’tig’ interface and displays the commits associated with the specified branch.
Example output:
commit: 05738fc329d3a75d64yx9ah4b10cba4430a0318a
Author: John Doe <john.doe@example.com>
Date: Mon Oct 11 12:34:56 2021 -0400
Update README.md
commit: 6c64a2d9ecc1b4a21ydx0vt628cc97553dd76a23
Author: John Doe <john.doe@example.com>
Date: Wed Oct 06 15:43:21 2021 -0400
Initial commit
Use case 3: Show the history of specific files or directories
Code:
tig path1 path2 ...
Motivation:
When you want to understand the commit history of specific files or directories in your project, this use case comes in handy. It allows you to narrow down and focus on the changes made to those specific files or directories.
Explanation:
By providing the paths to specific files or directories as arguments after the ’tig’ command, such as ’tig path1 path2’, you can view the commit history related to those paths. It opens the ’tig’ interface and displays the commits associated with the given paths.
Example output:
commit: 05738fc329d3a75d64yx9ah4b10cba4430a0318a
Author: John Doe <john.doe@example.com>
Date: Mon Oct 11 12:34:56 2021 -0400
Update README.md
commit: 6c64a2d9ecc1b4a21ydx0vt628cc97553dd76a23
Author: John Doe <john.doe@example.com>
Date: Wed Oct 06 15:43:21 2021 -0400
Initial commit
Use case 4: Show the difference between two references (such as branches or tags)
Code:
tig base_ref..compared_ref
Motivation:
When you want to compare the difference between two references, such as branches or tags, this use case is useful. It helps you analyze the changes made between the two references, providing a better understanding of the code changes.
Explanation:
The ’tig’ command allows you to compare the difference between two references by specifying them as arguments after the ’tig’ command, separated by two dots (..), such as ’tig base_ref..compared_ref’. It opens the ’tig’ interface and displays the commits and changes between the two references.
Example output:
commit: 6c64a2d9ecc1b4a21ydx0vt628cc97553dd76a23
Author: John Doe <john.doe@example.com>
Date: Wed Oct 06 15:43:21 2021 -0400
Initial commit
Use case 5: Display commits from all branches and stashes
Code:
tig --all
Motivation:
Sometimes you want to have a holistic view of the entire Git repository, including commits from all branches and stashes. This use case enables you to see all the changes made across different branches and stashes.
Explanation:
By using the ‘–all’ flag after the ’tig’ command, such as ’tig –all’, you can display commits from all branches and stashes. It opens the ’tig’ interface and shows the commit history from all available branches and stashes.
Example output:
commit: 05738fc329d3a75d64yx9ah4b10cba4430a0318a
Author: John Doe <john.doe@example.com>
Date: Mon Oct 11 12:34:56 2021 -0400
Update README.md
commit: 6c64a2d9ecc1b4a21ydx0vt628cc97553dd76a23
Author: Jane Smith <jane.smith@example.com>
Date: Fri Oct 08 09:12:34 2021 -0400
Add new feature
commit: a57cda18ae87200431xztsg842e7f9d76b4b12d
Author: John Doe <john.doe@example.com>
Date: Wed Oct 06 15:43:21 2021 -0400
Initial commit
Use case 6: Start in stash view, displaying all saved stashes
Code:
tig stash
Motivation:
When you have saved stashes in your Git repository, this use case allows you to easily access and manage them. It helps you keep track of the changes you have stashed for later use.
Explanation:
By using the ‘stash’ argument after the ’tig’ command, such as ’tig stash’, you can start the ’tig’ interface in the stash view, which displays all the saved stashes. It allows you to navigate through the stashes and apply or drop them as needed.
Example output:
stash: stash@{0}
Author: John Doe <john.doe@example.com>
Date: Mon Oct 11 12:34:56 2021 -0400
WIP: Work in progress
stash: stash@{1}
Author: Jane Smith <jane.smith@example.com>
Date: Fri Oct 08 09:12:34 2021 -0400
Feature implementation
Conclusion:
The ’tig’ command is a powerful tool for visualizing and navigating the Git repository history in a text-mode interface. By using various arguments and options, you can explore different aspects of the history, compare changes, and manage stashes effectively. Understanding the use cases and examples provided in this article will help you leverage the ’tig’ command to enhance your Git workflow.