
#Git can be intimidating at times. Because there are so many commands and details to learn. However, although Document has a lot of content, it is still very easy to read. Once you get over the initial feeling of overwhelm, you'll feel significant progress. Here is a list of 15 Git commands you may not know yet, hopefully they will help you become proficient in Git.
1. Modify the latest commit
git commit --amend
—-amend allows you to make staged changes (such as adding Forgotten files) are appended to the previous commit. Adding --no-edit will modify the last commit but not change its commit message. If there are no changes, --amend will allow you to re-enter the last commit message.
More information: git help commit.
2. Interactively add selected portions of files
git add -p
-p (or — patch) allows interactive selection of portions of each trace file to commit. This way each commit only contains relevant changes.
More information:git help add
3. Interactively hide selected portions of files
git stash -p
Similar to git-add, you can interactively select parts of each file to be tracked using the --patch option.
More information:git help stash
4. Hide untracked files
git stash -u
By default, untracked files are not included when storing. In order to change this behavior and include those files, you need to use the -u parameter. There is also a -a (-all) parameter that can store all untracked and ignored files, which is usually something you don't need.
5. Interactively restore selected portions of files
git checkout -p --patch` can be also used to selectively discard parts of each tracked file. I aliased this command as `git discard
More information: git help checkout
6. Switch to the previous branch
git checkout -
This command allows you to quickly switch to a previously checked out branch. Usually - is an alias for the previous branch. It can also be used with other commands. I created an alias co for checkout so it could be git co -
7. Restore all local Change
git checkout .
If you are sure you can discard all local changes, you can use . to do it all at once. But it's a good practice to always use checkout --patch.
8. Show changes
git diff --staged
This command displays all staged changes (changes that have been added to the index), unlike git diff Compared to git diff which only shows changes in the working directory (no changes in the index).
More information: git help diff
9. Rename the branch locally
git branch -m old-name new-name
If you want to rename the currently checked out branch, you can shorten the command to the following form:
git branch -m new-name
More information: git help branch
10. Rename a branch remotely
In order to rename a branch remotely, after renaming the branch locally, you need to delete the branch remotely first, and then push the renamed branch again.
git push origin :old-name git push origin new-name
11. Open all conflicting files at once
Resetting the baseline may cause conflicts, the following command will open and require you to resolve these All conflicting files.
git diff --name-only --diff-filter=U | uniq | xargs $EDITOR
12. What has changed?
git whatchanged —-since=‘2 weeks ago’
This command will display a log containing the differences introduced by each commit over the last two weeks.
13. Remove files from previous commit
You can do this by combining rm and commit - -amend command to quickly delete accidentally committed files from the last commit:
git rm —-cached <file-to-remove> git commit —-amend</file-to-remove>
14. Find the branch
git branch --contains <commit></commit>
The The command will display all branches containing a specific commit.
15. Optimize the repository locally
git gc --prune=now --aggressive
More information: git help gc
Summary
Although I like the CLI very much, I still strongly recommend using Magit to further improve the efficiency of your use of Git. It's one of the best software I've ever used.
You can also view an excellent overview of the Git workflow through the help command. Please read carefully!
git help workflows
英文原文地址: https://zaiste.net/15-git-commands-you-may-not-know/
为了保证的可读性,本文采用意译而非直译。
教程推荐:《Git教程》
The above is the detailed content of 15 Git commands you may not know yet. For more information, please follow other related articles on the PHP Chinese website!
GitHub: A Hub for Open Source and Software DevelopmentApr 15, 2025 am 12:10 AMGitHub is a Git-based version control system hosting platform that provides version control, collaborative development and community communication functions. Using GitHub can improve development efficiency and code quality.
Git and GitHub: What's the Relationship?Apr 14, 2025 am 12:10 AMGit and GitHub are different tools: Git is software for version control, and GitHub is an online platform based on Git. 1.Git allows you to track file changes and collaborative development. 2. GitHub provides code hosting and collaboration tools to enhance team development efficiency.
GitHub: The Platform for Developers and ProjectsApr 13, 2025 am 12:01 AMThe core features of GitHub include version control, branch management, code review, issue tracking and project management. 1. Version control and branch management are based on Git, allowing tracking of code changes and experimental development. 2. Code review is implemented through PullRequest to improve code quality and team collaboration. 3. Issues tracking and project management are carried out through Issues and the project management board to improve project transparency and traceability.
GitHub in Action: Examples and Use CasesApr 12, 2025 am 12:16 AMGitHub is a powerful tool to improve the efficiency and quality of software development. 1) Version control: manage code changes through Git. 2) PullRequests: Conduct code review and improve code quality. 3) Issues: Track bugs and project progress. 4) GitHubActions: Automate the construction, testing and deployment process.
Git vs. GitHub: Version Control and Code HostingApr 11, 2025 am 11:33 AMGit is a version control system, and GitHub is a Git-based code hosting platform. Git is used to manage code versions and supports local operations; GitHub provides online collaboration tools such as Issue tracking and PullRequest.
What is Git in simple words?Apr 09, 2025 am 12:12 AMGit is an open source distributed version control system that helps developers track file changes, work together and manage code versions. Its core functions include: 1) record code modifications, 2) fallback to previous versions, 3) collaborative development, and 4) create and manage branches for parallel development.
Is Git the same as GitHub?Apr 08, 2025 am 12:13 AMGit and GitHub are not the same thing. Git is a version control system, and GitHub is a Git-based code hosting platform. Git is used to manage code versions, and GitHub provides an online collaboration environment.
How to use GitHub for HTML?Apr 07, 2025 am 12:13 AMThe reason for using GitHub to manage HTML projects is that it provides a platform for version control, collaborative development and presentation of works. The specific steps include: 1. Create and initialize the Git repository, 2. Add and submit HTML files, 3. Push to GitHub, 4. Use GitHubPages to deploy web pages, 5. Use GitHubActions to automate building and deployment. In addition, GitHub also supports code review, Issue and PullRequest features to help optimize and collaborate on HTML projects.


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

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools







