Git Common Tips and Cases

**1. Automatically remove pre-commit hooks when committing ** 🔗︎

  • Use the command:
git commit -n 
  • -n is short for --no-verify, which is used to skip the pre-commit hooks.

**2. Switching to the previous branch 🔗︎

  • Quickly switch to the previous branch:
git checkout - 

— -# **3.

**3. Clearer branch management ## **3. 🔗︎

  • Before local push, it is recommended to pull remote code using:
git pull -r 
  • -r is an abbreviation for --rebase, which makes the branch history clearer and avoids unnecessary merge commits.

4. Cherry Pick 🔗︎

Function* 🔗︎

  • Applies a set of changes from another branch to the current branch.

**Commonly used commands### 🔗︎

  • Apply a single commit:
git cherry-pick <hasha> 
  • Apply a series of commits (from <hasha> to <hashb>):
git cherry-pick <hasha>^... <hashb> 

**5. Viewing commit differences 🔗︎

  • View the diff between two branches or commits:
git diff xxx.. .yyyy 
  • This command allows you to see the differences between ``git pull’’ commits.

6. Case Study: Quickly Stemming a Release Issue **Scenario. 🔗︎

Scenario 🔗︎

  • When there is a problem with a release (a tag), how do you fix it quickly?

Solution ### Solution ### **Solution 🔗︎


**7. Fix commit log non-conformance 🔗︎

  • Use git rebase to change the author information of a commit record: ``bash git rebase master –exec=“GIT_COMMITTER_EMAIL=your email GIT_COMMITTER_NAME=your name git commit –amend –author=‘Your fancy name ’ -C HEAD fancy name ’ -C HEAD”
 - Replaces ``your mailbox``, ``your name``, and ``your filename`` with the actual information.
 - This command will uniformly change the author information for all commit records to the specified values.