[TIPS] Tig: A Simple Boost for Your Git Workflow

By datnq, at: 14:58 Ngày 25 tháng 3 năm 2024

Thời gian đọc ước tính: 6 min read

Tig: A Simple Boost for Your Git Workflow
Tig: A Simple Boost for Your Git Workflow

Tig: A Simple Boost for Your Git Workflow


The tig command is a text-mode interface for git, providing an interactive and visual way to navigate and manage git repositories. It simplifies viewing commit history, diffs, and branches, allowing for easier code reviews and repository exploration. Tig supports various modes for different tasks, making it a handy tool for developers working with git. 

 

Install Tig

 

Ubuntu

To install Tig on Ubuntu, you can utilize the APT package manager. Open a terminal and execute the following command:

sudo apt-get install tig

 

macOS

For macOS users, Tig can be installed via Homebrew. Open a terminal and run the following command:

brew install tig

 

Basic Usage

 

After successful installation, you can initiate Tig by typing tig in the terminal.

tig_show

 

As depicted above, Tig appears similar to git log but offers more comprehensive support. Next, you can select any commit or branch. Press enter to select.

tig_show_detail_commit

 

Operating Tig is akin to navigating in Vim. Use up and down arrows for the left display and j, k for the right.

In addition to the basic display shown above, below are some fundamental tips for using Tig.

 

1. Listing Branches and Checking Out Between Them

To view a list of branches and switch between them, utilize the following shortcuts:

  • tig: Open Tig.

  • Press r: View a list of branches.

    tig_show_list_branch

 

        Here, you can see both local and remote branches displayed with different colors.

  • Press Shift + c: Checkout to a different branch.tig_checkout_branch

 

  • Confirm when prompted by entering y.

 

2. Adding Files

To stage files for changes, use the following shortcuts:

  • tig: Open Tig.

  • Press Shift + s: Select files to add to the index.

    tig_add_file

 

  • Press u to add the selected files. Newly added files will display A. Modified files will display M and after staging, they will display C. Pressing u again will revert from staged to unstaged.

 

3. Committing Code

To commit code, follow these steps:

  • tig status: View the status of changes.

  • Press Shift + c: Initiate the commit process.

    tig_commit

 

  • Enter :wq to save and exit.

  • Use git push to push the commits to the repository.

 

4. Viewing ID of a Commit

To view ID of a commit, follow these steps:

  • tig: Open Tig.

  • Type :toggle id to display commit IDs.

    tig_show_id

 

  • Select the commit you want to view using arrow keys.

  • Press Enter to see detailed information.

 

5. Cherry-Picking

To cherry-pick a commit, follow these steps:

  • tig: Open Tig.

  • Select the commit you want to cherry-pick.

  • Press Shift + c to initiate cherry-picking.

    tig_cherry_pick

 

  • Confirm when prompted by entering y.

 

Other Useful Commands:

 

  • Tig blame  < file >:

    This command is particularly useful for investigating the history of changes made to a specific file within the repository. It provides detailed insights into who made each change, when the change was made, and the corresponding commit information.

 

  • Tig  < branch1 > ... < branch2 >:

    This command enables users to compare code differences between different branches within the repository. By specifying the branches to compare, users can easily identify variations in code between the selected branches.

 

  • Tig stash:

    The stash command in Tig is essential for managing changes in a Git repository. It allows users to temporarily store modifications that are not yet ready to be committed. By stashing changes, users can maintain a clean working directory without losing any work in progress.

 

References:


Theo dõi

Theo dõi bản tin của chúng tôi và không bao giờ bỏ lỡ những tin tức mới nhất.