Implementation of GIT rebase – I merging multiple commit

Time:2020-10-30

brief introduction

In the daily development, code changes are frequent. Sometimes you want to merge the previous submission into one submission. Here, you can use the GIT rebase – I command to complete it. Of course, the GIT rebase command is not only used for merge and commit, but also has many uses, such as git rebase Onto pastes a commit to another branch and so on. Here we mainly introduce merge commit.

Command introduction

Rebase is variable base
Git rebase – I command can compress and merge multiple commits
Format:git rebase -i [startpoint] [endpoint]

Where – I means – interactive, that is, an interactive interface will pop up to allow users to edit and complete the merge operation. In [startpoint] [endpoint], an editing interval is specified. If [endpoint] is not specified, the end point of the interval is the commit pointed to by the current branch head (Note: this interval specifies an interval that is opened before and closed after).

After viewing the GIT log, you can use the following command

//Merge from current head to 15f745b (commit ID)
git rebase -i 15f745b
Or:
//Merge the last two commits
git rebase -i HEAD~2

After executing this command, you will jump to a VI editor

The tips are:

  • Pick: keep the commit (abbreviation: P)
  • Reword: keep the commit, but I need to modify the comment of the commit (abbreviation: R)
  • Edit: keep the commit, but I’m going to stop and modify the commit (not just the comments) (short form: e)
  • Squash: merge the commit with the previous commit (abbreviation: s)
  • Fixup: merge the commit with the previous commit, but I don’t want to keep the comment information of the commit (abbreviation: F)
  • Exec: execute shell command (abbreviation: x)
  • Drop: I want to discard the commit (abbreviation: D)

Practical operation

Here, input git rebase – I head ~ 2 at the terminal, and the head ~ 2 here means to merge the last two commits. If you want to merge the last three commits, modify it to git rebase – I head ~ 3

What you need to do is change the pick on the second line to s, “s” is the abbreviation for “squash,” which means compressing this commit to the last commit

After saving, this will pop up

Change the content below this is the commit message ා 2 to the summary you want to submit

Finally, save and exit

This article about the implementation of GIT rebase – I merge multiple submission is introduced here. For more related git rebase – I merge multiple submission content, please search the previous articles of developeppaer or continue to browse the related articles below. I hope you can support developeppaer more in the future!