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!

Git and GitHub are essential tools for modern developers. 1. Use Git for version control: create branches for parallel development, merge branches, and roll back errors. 2. Use GitHub for team collaboration: code review through PullRequest to resolve merge conflicts. 3. Practical tips and best practices: submit regularly, submit messages clearly, use .gitignore, and back up the code base regularly.

Git and GitHub are not the same thing: Git is a distributed version control system, and GitHub is an online platform based on Git. Git helps developers manage code versions and achieve collaboration through branching, merge and other functions; GitHub provides code hosting, review, problem management and social interaction functions, enhancing Git's collaboration capabilities.

After installing Git, in order to use more efficiently, the following settings are required: Set user information (name and mailbox) Select text editor Set external merge tool Generate SSH key settings Ignore file mode

Resolve: When Git download speed is slow, you can take the following steps: Check the network connection and try to switch the connection method. Optimize Git configuration: Increase the POST buffer size (git config --global http.postBuffer 524288000), and reduce the low-speed limit (git config --global http.lowSpeedLimit 1000). Use a Git proxy (such as git-proxy or git-lfs-proxy). Try using a different Git client (such as Sourcetree or Github Desktop). Check for fire protection

Causes of slow Git downloads include poor network connections, Git server problems, large files or large submissions, Git configuration issues, insufficient computer resources, and other factors such as malware. Workarounds include improving network connectivity, adjusting firewall settings, avoiding downloading unnecessary files or submissions, optimizing Git configuration, providing adequate computer resources, and scanning and removing malware.

How to update local Git code? Use git fetch to pull the latest changes from the remote repository. Merge remote changes to the local branch using git merge origin/<remote branch name>. Resolve conflicts arising from mergers. Use git commit -m "Merge branch <Remote branch name>" to submit merge changes and apply updates.

Steps to update git code: Check out code: git clone https://github.com/username/repo.git Get the latest changes: git fetch merge changes: git merge origin/master push changes (optional): git push origin master

You can delete a Git branch through the following steps: 1. Delete the local branch: Use the git branch -d <branch-name> command; 2. Delete the remote branch: Use the git push <remote-name> --delete <branch-name> command; 3. Protected branch: Use git config branch. <branch-name>.protected true to add the protection branch settings.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment