Git practical tips: merge multiple commits into one

Use the git rebase -i command to merge multiple submissions from the last submission into one.

Example of use:
My current submission record is as follows, there are 3 submissions in total, the following will merge these 3 submissions into one:
Pending status

Enter the following command:

git rebase -i HEAD~3

Then the target editing window will pop up:

This is a text edited by vim and needs to be edited with vim commands.

  • First, enter the i command to enter the editing mode.
  • What we need to pay attention to is the information starting with pick on the top few lines. Need to change the pick except the first line to s.
  • Then press the esc key to exit the input mode, enter: (English colon) to enter the bottom line command mode
  • Then enter wq to save and exit

pick or s

After that, the following interface will be displayed for submitting annotation processing.

We delete all the comments except one, and the effect after deletion is as follows:

Final note
Then save and exit in the same way.

This is the end, and then use git log to check the submission record and find that it has become a record. It should be noted that this record is the earliest one of the three times, and it shows the same submission time as the first time. But it is also a new submission record, and you can notice that its submission record number is different from the previous three times.

Note that if the current branch has been pushed to the remote before, you need to use git push -f to push the rebase branch to the remote.

If you have any questions and your own opinions, please feel free to put forward in the comment area. I hope to have more exchanges with you.

Guess you like

Origin blog.csdn.net/vxzhg/article/details/105448190