Don’t panic if Git commits wrong, git commit --amend modifies the git commit record

In the actual work scenario, there may be a file error in the process of submitting the code, and it needs to be resubmitted.
At this time, git commit --amend will come in handy

After git log, you can see the git history you have submitted before:
insert image description here
Next, enter wq in bash to exit the log status and execute:

git commit --amend

At this time, the following content will appear in bash:
insert image description here
Among them, second commit is the description of your last commit, and the following is the description information, which tells you the file information you submitted last time, etc., which can be ignored. Next, if you want to modify the description information. Type directly: i, and enter the input mode at this time, and it becomes like this:
insert image description here

You can use the up and down keys on the keyboard to go to the line where the description is located, and then modify it:
insert image description here
after the modification is completed, press the Esc key to exit the editing mode, type :wq, press Enter to exit and save the modification, and complete the submission. This is your git log and look at the commit log:
insert image description here
the commit description has been modified, and the original git version is gone.
But there is one thing to pay attention to, that is, this operation will change your original commit id.

Guess you like

Origin blog.csdn.net/weixin_44248187/article/details/125553230