How to modify Git commit information: Modify the last commit information: git commit --amend -m "New commit information" Submission information before modifying: git rebase -i HEAD~n, select reward to modify information (use with caution, especially when multi-person collaboration) Standardize commit information: Follow the 50/72 rules and describe the modification content clearly and concisely
Rewrite the Git commit message and don’t let history be shamed!
Many times, after submitting the code, I find that the commit message is written in a messy way, or it is simply wrong. This feels like I find that the title is wrong after writing the paper, which makes people crazy. Don't worry, Git provides a way to modify commit message, allowing you to gracefully correct history and maintain the cleanliness of your code base. After reading this article, you will be able to easily master the skills of modifying commit information and understand the principles behind it to avoid falling into the pit again.
Let me first talk about a basic concept: Git's commit record is immutable, which sounds rigid, but in fact, the cleverness of Git is that it does not really modify history, but creates a new commit to replace the old one. After understanding this, many problems will be solved.
The most commonly used method is git commit --amend
. This thing is like a "regret medicine" that can modify the message you submitted last time. For example, if you just submitted a commit and found that the description was written incorrectly, then:
<code class="bash">git commit --amend -m "This is the corrected commit message"</code>
This line of command will create a new commit. The content of the new commit is exactly the same as before, except that the message has been modified. The original commit is like being erased by a time machine, leaving only the revised version. Simple and crude, efficient and practical. Remember that the -m
parameter is followed by the new commit message.
But what if you want to modify the previous commit? --amend
is powerless. At this time, you need to use git rebase -i HEAD~n
(where n represents the number of commits you want to modify). This command will open an interactive interface, allowing you to choose which commit to modify. Selecting reword
can modify the corresponding commit message. This is an advanced operation, please be careful! Especially if you have pushed to the remote repository, don't rebase directly, otherwise it will cause huge trouble to collaboration. The correct way is to first git pull --rebase
, and then perform rebase operations.
Speaking of this, I have to remind you that revising history is not a joke. Especially for projects that are collaborated by multiple people, modifying the history of shared branches at will, which will cause your teammates to collapse. Therefore, developing good submission habits and carefully checking the commit message before submitting is the king. Instead of making remedies afterwards, it is better to do it in advance.
Let’s talk about some pitfalls:
- The risk of
git rebase -i
: it rewrites the commit history, and if someone has already done the work based on the commit you modified, it will create conflicts and even cause the project to crash. So, unless absolutely necessary, don't usegit rebase -i
on public branches. - The specification of commit message: A good commit message should clearly and concisely describe what this commit did, why it was done, and how it was done. Following certain specifications, such as the 50/72 rule (the subject line does not exceed 50 characters, the description line does not exceed 72 characters), can greatly improve the readability and maintainability of the code.
Finally, I would like to say that the power of Git is its flexibility and controllability, but this flexibility and controllability also requires us to use it with caution. Only by mastering Git's commands and understanding the principles behind them can you truly control it and make it a weapon for you to improve efficiency, rather than a burden that makes you a headache. Remember, write a commit message, starting now!
The above is the detailed content of git how to modify the description of commit. For more information, please follow other related articles on the PHP Chinese website!

GitHub is a distributed version control system based on Git, providing the core features of version control, collaboration and code hosting. 1) Creating repositories, cloning, committing and pushing changes is the basic usage. 2) Advanced usage includes using GitHubActions for automation, deploying static websites in GitHubPages, and using security features to protect code. 3) Common errors such as merge conflicts, permission issues and network connection issues can be debugged by manually resolving conflicts, contacting the warehouse owner and setting up a proxy. 4) Methods to optimize workflows include using branching strategies, automated testing and CI/CD, code review, and keeping documentation and annotations clear.

Git and GitHub are different tools: Git is a distributed version control system, and GitHub is an online collaboration platform based on Git. Git manages code through workspaces, temporary storage areas and local warehouses, and uses common commands such as gitinit, gitclone, etc. GitHub provides functions such as code hosting, PullRequest, IssueTracking, etc. The basic process includes creating repositories, pushing code, and collaborating with PullRequest.

Git and GitHub are key tools for modern software development. Git provides version control capabilities to manage code through repositories, branches, commits and merges. GitHub provides code hosting and collaboration features such as Issues and PullRequests. Using Git and GitHub can significantly improve development efficiency and team collaboration capabilities.

Git is a distributed version control system developed by Linus Torvaz in 2005, and GitHub is a Git-based code hosting platform founded in 2008. Git supports branching and merges through snapshot management files, and GitHub provides pull requests, problem tracking and code review functions to facilitate team collaboration.

Git and GitHub are key tools in modern software development. Git is a distributed version control system, and GitHub is a Git-based code hosting platform. Git's core features include version control and branch management, while GitHub provides collaboration and project management tools. When using Git, developers can track file changes and work together; when using GitHub, teams can collaborate through PullRequests and Issues.

GitHubiscrucialforsoftwaredevelopmentduetoitscomprehensiveecosystemforcodemanagementandcollaboration.Itoffersversioncontrol,communitysupport,andtoolslikeGitHubActionsandPages.Startbymasteringbasicslikecreatingarepository,usingbranches,andautomatingwo

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.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor
