Home > Article > Development Tools > 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
You can also get the yarn.lock file from a commit
git checkout 9146467 -- yarn.lock
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
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
-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.
If you use git checkout . all tracked changes will be cleared. Use the following command to clear all untracked changes:
git clean -f -d
5. Print a visual log
Use the following command to print out Visualized log
git log --pretty=oneline --graph --decorate --all
(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
The above<commit> </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
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='FEB 10 2016' --until='FEB 19 2016'
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 's/^alias\.//g'
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"
This example will find all submissions containing config.menu_items
10. Ultimate Skill
git help -g
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></concept>
. The column on the left is <concept> </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 工作流概述
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!