This is the first day of my participation in the August Challenge. For details, see:August is more challenging

preface

There is always a lot of debate about Git Rebase.

Passerby A: “our team never use Git rebase, just like nothing, the company is also good, but also making A lot of money?”

Passerby B: “Git rebase is good! Git rebase is god!”

Since there is so much debate, let’s spend the least time together to find out what Git Rebase can do for me.


Usage 1: Merge multiple commits

Scenario 1: Xiao Ming develops a very complex function E to prevent code loss due to force majeure. With good habits, Xiao Ming submits the code every day with records of E-1, E-2 and E-3.

FIG. 1

Finally excellent Xiaoming finished development, but he has code cleanliness, every time after development, will go to pull away from their own methods, to see if the code is more streamlined, he even submitted records to do the ultimate beautiful.

Figure 2

Operation method:

The first step:git logTo find these three submissions, of course, you can also use more accurategit reflog, the specific difference between the two will not be repeated in this article.

Step 2: According to the observation is the last three submissions,git rebase -i HEAD~3, the 3 in the command represents the last three submissions;

Step 3: EnteriEnter the edit mode and go to the last twopickChanged to:s, press theesc, manual input:wqNow that the first step of the merge is successful, you need to modify the commit record for this merge.

Step 4: EnteriEnter edit mode and delete or add unnecessary items#Indicates the comment line. When you’re done editing, pressesc, manual input:wq, the merger is successful

Use 2: Turn a disordered cross submission record into a graceful straight line

Here we have to comparegit rebaseandgit merge:

Without further ado, go straight to the result:

Let’s start with git merge:

Git Rebase:

Speaking part

However, the actual operation is quite simple: do it under two branches: Git rebase one brings all commits from the current branch to the front, creating a nice commit record.

“Love, Hate”

No longer have to endure this love and hate intricate “emotional interweave”

A free branch words refer to: www.cnblogs.com/yxhblogs/p/…