Home > Development Tools > git > 10 Git tips to improve efficiency

10 Git tips to improve efficiency

青灯夜游
Release: 2019-11-30 16:16:03
forward
3249 people have browsed it

10 Git tips to improve efficiency

1. Check out a single file from a branch

Have you ever corrupted a file? Want to start over?

Or the required file is in another branch?

The following command allows you to get the file directly from a certain branch.

git checkout some-other-branch -- yarn.lock
Copy after login

You can also get the yarn.lock file from a commit

git checkout 9146467 -- yarn.lock
Copy after login

10 Git tips to improve efficiency

Compared to cherry-pick get For all files of a certain commit, this technique can only get the file you want.

2. Filter out merge commits when viewing logs

When merge is used, a new commit will be generated. Sometimes this commit is very annoying. . If you want to filter out these merged commits when viewing the log, you can use the following command:

git log --oneline --no-merges
Copy after login

10 Git tips to improve efficiency

3. Rewrite the last commit message

If the commit information is not well written or has typos in your latest submission, you can use the following command to modify it:

git commit -v --amend
Copy after login

-v here is optional, it can provide some additional information to help you describe the commit message

4. Clear all untracked changes

First explain a concept:

If you create a new file that does not exist in the git history before, then this file is an untracked change. In order to track this file, you need to commit it to git.

10 Git tips to improve efficiency

If you use git checkout . all tracked changes will be cleared. Use the following command to clear all untracked changes:

git clean -f -d
Copy after login

5. Print a visual log

Use the following command to print out Visualized log

git log --pretty=oneline --graph --decorate --all
Copy after login

(Translator’s note: It’s just a rough look, but it’s still not comparable to sourcetree’s~)

6. Query Git for changelog

This command can query Git who made what changes between two commits. It looks like a changelog

git shortlog <commit>..HEAD
Copy after login

The above<commit> Fill in the hash value of the commit to find out the changes between the commit and HEAD. The HEAD after .. can also be omitted

10 Git tips to improve efficiency

You can also use git shortlog HEAD~20.. to get the records of the last 20 commits

7. Query the records of the specified date log

You may need to query the git log between two days. In this case, you can use the git log command with the --since and --util identifiers

if If you want to query the logs between February 10, 2016 and February 19, 2016, you can run:

git log --since=&#39;FEB 10 2016&#39; --until=&#39;FEB 19 2016&#39;
Copy after login

8. List all git aliases

Sometimes you may forget the git alias you set before. Although the following command is not a git function, it can help you find all git aliases

git config -l | grep alias | sed &#39;s/^alias\.//g&#39;
Copy after login

9. Query commits that contain a certain keyword

If you know what the code you are looking for is specifically written, or you know a special keyword, you can use It comes to search.

git log -S"config.menu_items"
Copy after login

This example will find all submissions containing config.menu_items

10. Ultimate Skill

git help -g
Copy after login

You can see a list of git tutorials similar to the one below. You can open the specified tutorial webpage in the browser through git help <concept>. The column on the left is <concept> Name

The common Git guides are:

   attributes   定义 Git 路径的属性
   everyday    每天学点有用的 Git 命令
   glossary     一个 Git 词汇表
   ignore        指定 Git 忽略文件
   modules     定义 Git 子模块
   revisions     指定 Git 的修订版和范围
   tutorial       Git 的教程介绍 (for version 1.5.1 or newer)
   workflows   一个推荐的 Git 工作流概述
Copy after login

This article comes from the git tutorial column, welcome to learn!

The above is the detailed content of 10 Git tips to improve efficiency. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
git
source:savokiss.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template