Usage scenarios

When we make a requirement, there is a problem for a variety of reasons: the same requirement is split into multiple Commit commits, which are spliced together to make a complete feature. To avoid too many commits causing versioning chaos and make the commit log look cleaner, it is generally recommended to merge multiple commits into a single commit.

steps

Suppose we make the following three commits, and we want to combine the first two commits — COMMIT BD61DAE and commit D9A0C84 — into one commit.

Enter the command:git rebase -i commitIdHere commitId is the commit record commitId, 3BE0e8F, that precedes the multiple records you want to merge.Press Enter to enter vim editing modeEach line consists of three parts: the command name + commit hash + commit message, and the command prompt begins with a #.

Command Description Pick: retain the commit (p) squash: Merge the commit and the previous commit (S)Copy the code

Change COMMIT D9A0C84 to S or squashThen press Esc to return to normal mode and you’ll find the one in the lower left corner- insert -Out of sight. Then enter :wq to save the configuration and exit.

Vim editor exit: Q! -> Forced exit without saving :wq -> Save and exit :wq! -> Forcibly save the Settings and exitCopy the code

Then it enters vim edit mode for the second timeDelete the Commit Messages B and C, rewrite the commit information, and save and exit as before.When the inputgit logLooking at the commit log, you can see that multiple Commits have been merged into one

The last

If you don’t understand what needs to be improved or have other opinions, please put forward in the comment section. I hope we can communicate and learn together.