In some controlled projects, after submitting the code to git server, it needs to be verified before it is officially incorporated into the version. Generally, Gerrit is used for verification operation.

If the submitted code is not approved, the submission needs to be modified again. Since it is the same problem, we may not want to generate multiple commits, which will appear scattered and incomplete. Therefore, we want to commit the changes on the local commit, rather than add a new commit to the existing commit.

You can commit changes again on an existing commit with git commit –amend.

Git commit -m: git commit -m: git commit -m: git commit -m: git commit If you run git commit –amend, you will find the latest commit information. You can modify it or not. After committing, you can run git log to check, but no new commit is added. The hash value of the original commit is the same as the hash value of the previous commit.

The key description of the –amend option is as follows:

–amend Replace the tip of the current branch by creating a new commit. That is, the –amend option creates a new commit to replace the current most recent commit, as if the current most recent commit information had been modified.

You can see the git history you have previously committed:

Next, enter wq in bash to exit the log state and run:

   $ git commit --amend
Copy the code

The following will appear in bash:

Where, second commit is the description of your last submission, the following is the description of the last submission information, etc., can be ignored. And then if you want to change the description. Just type: I, and it goes into input mode and looks like this:

Use keyboard up and down keys to go to the line where the description is and then modify it:

After the modification is complete, press Esc to exit the editing mode, enter :wq, and press Enter to exit and save the modification. Git log: