git modifies the comment content of commit

To modify the commit comment content in Git, you can use the git commit --amend command. The specific steps are as follows:
1. View all commits
and run the git log --oneline command to view the hash value of the commit that needs to be modified.

2. Modify the last commit comment
Run the git commit --amend command to open the vim editor

Enter i to enter edit mode

Modification notes
Before modification:

After modification:


Press Esc to exit edit mode and type :wq! to save


Verify the modification results. Run git log --oneline to view the comments of the latest commit
. You can see that the modification has been successful at this time.


3. Modify a commit comment
As shown in the figure, modify the comment in the screenshot:

Run the git rebase -i <commit-hash> command to enter the interactive rebase interface.
commit-hash is the hash value generated each time the code is submitted. If we want to modify a certain submission, we can enter the last hash value of a certain submission, so that the vim interface displays the submission after the hash value, of course, we can also enter a range.

For example: what I input here is the hash value twice

enter:

Press i to enter the edit mode, change the pick command of the commit to be modified to the edit command, then Esc :wq! to save and exit (if you want to modify the comment of a commit, change the pick of that line to edit).


Run the git commit --amend command to modify the comment content, Esc :wq! Save and exit.

Run the git rebase --continue command to continue the rebase operation. (If you want to modify more than one at a time, you need to run the git rebase --continue command after modifying multiple times)

Run the git push --force command to push to the remote branch forcefully. Note: Modifying the comment content of the commit will modify the hash value of the commit, so it needs to be forced to push to the remote branch.

Run git log --oneline to verify whether the comment is modified successfully


ok, the modification is successful.
 

Guess you like

Origin blog.csdn.net/qq_41694204/article/details/131239611