LabHub

Blog

Git Tools Usage

한국어English日本語

Git Tools Usage

Git provides a variety of tools that enable more efficient version control. This article introduces how to use the major Git tools.

Revision Selection

Git allows you to select revisions in several ways.

Single Revision

To select a single revision, use the commit hash.

$ git show <commit_hash>

Short Hash

You can easily select a revision using a short hash.

$ git show <short_hash>

Branch References

Use branch names to reference revisions.

$ git show <branch_name>

RefLog Shortnames

Use RefLog shortnames to reference recent revisions.

$ git show HEAD@{2}

Ancestry References

Use ancestry references to select previous commits.

$ git show HEAD~2

Interactive Staging

You can use interactive staging to choose which changes to commit.

Staging and Unstaging Files

Stage or unstage files.

$ git add -i

Staging Patches

Stage patches.

$ git add -p

Stashing and Cleaning

Temporarily save work in progress and clean the working directory.

Stashing Your Work

Stash the current work.

$ git stash

Applying a Stash

Re-apply the saved work.

$ git stash apply

Dropping a Stash

Delete the saved work.

$ git stash drop

Creating a Branch from a Stash

Create a new branch and apply the stash.

$ git stash branch <branch_name>

Cleaning the Working Directory

Clean the working directory.

$ git clean -fd

Signing Your Work

Git allows you to add GPG signatures to commits and tags.

Introduction to GPG

Use GPG to add signatures to commits and tags.

$ git config --global user.signingkey <GPG_key>

Signing Tags

Sign a tag.

$ git tag -s <tag_name> -m "message"

Verifying Signatures

Verify a signature.

$ git tag -v <tag_name>

Signing Commits

Sign a commit.

$ git commit -S -m "message"

Searching

You can perform various searches within a Git repository.

Git Grep

Search for text within files.

$ git grep "search_text"

Search for text within the log.

$ git log -S "search_text"

Search for the change history of specific lines.

$ git log -L :<function_name>:<file>

Rewriting History

You can rewrite history by changing commit messages, reordering commits, and more.

Changing the Last Commit

Change the last commit message.

$ git commit --amend -m "new_message"

Changing Multiple Commit Messages

Change multiple commit messages.

$ git rebase -i HEAD~n

Reordering Commits

Reorder commits.

$ git rebase -i HEAD~n

Squashing Commits

Squash multiple commits into one.

$ git rebase -i HEAD~n

Splitting a Commit

Split a single commit into multiple commits.

$ git rebase -i HEAD~n

Rewriting History

Use powerful history rewriting tools.

$ git filter-branch

Reset Demystified

You can perform various operations using the Git reset command.

The Three Trees

Understand Git's three trees: HEAD, Index, and Working Directory.

The Workflow

Manage the workflow using the reset command.

$ git reset --hard <commit>

Reset with a Path

Reset a specific path.

$ git reset <path>

We have covered the basic usage of Git tools. You can use these tools to manage your work in Git more efficiently.

Quiz

Q1: What is the main topic covered in "Git Tools Usage"? Learn the basic usage of Git tools.

Q2: What is Revision Selection? Git allows you to select revisions in several ways. Single Revision To select a single revision, use the commit hash. Short Hash You can easily select a revision using a short hash. Branch References Use branch names to reference revisions.

Q3: Explain the core concept of Interactive Staging. You can use interactive staging to choose which changes to commit. Staging and Unstaging Files Stage or unstage files. Staging Patches Stage patches.

Q4: What are the key aspects of Stashing and Cleaning? Temporarily save work in progress and clean the working directory. Stashing Your Work Stash the current work. Applying a Stash Re-apply the saved work. Dropping a Stash Delete the saved work. Creating a Branch from a Stash Create a new branch and apply the stash.

Q5: How does Signing Your Work work? Git allows you to add GPG signatures to commits and tags. Introduction to GPG Use GPG to add signatures to commits and tags. Signing Tags Sign a tag. Verifying Signatures Verify a signature. Signing Commits Sign a commit.

Comments

No comments yet.

Sign in to leave a comment