Command line --git--how to merge multiple commits into one commit

Reference: https://blog.csdn.net/qq_50652600/article/details/120800309
In our usual development, we will inevitably have to deal with git when submitting code, so we must first pull the latest code from the pre-release branch (companies generally use pre name, here is master for the convenience of demonstration), and then cut a function branch (gongeng) of our own on it for development.

    但是如果我们一个功能模块开发完了之后,肯定提交了许多次,如果我们想把这么多提交记录都merge到我们的master分支上,肯定是不友好和不雅观的。所以我们需要将我们许多次的提交记录合成一次的提交记录,在合并到我们的pre分支上。(多说一句:一般自己的功能分支上开发完成之后,肯定是先合并到测试分支上先测试通过的,然后再将功能分支的代码合并到预发分支,这里为了方便,省去了测试分支)

If you feel that the command line operation is cumbersome and you don’t want to use the command line, you can use the idea graphical tool to operate: idea–git–how to combine multiple commits into one point 1 Enter the warehouse to view the commit (command: git log) From this we can see that I have submitted 3 records on my own functional branch, and they are arranged in reverse
chronological
insert image description here
order

2 Use the rebase command to rebase (command: git rebase -i HEAD~3)
insert image description here
pick: keep the commit

squash: Merge the commit with the previous commit

Therefore, if we want to combine these three price increases into one submission, we need to change the pick of commit2 and commit3 to squnsh (abbreviated "s"). As shown in the figure below:
insert image description here
Tip: Press the "i" key to enter the vim editing mode for modification. After the modification is completed, press the "esc" key to exit, and press ":" again to enter the bottom line command mode. After entering "wq" to save, the commit message information interface will automatically appear. At this point, we can keep or delete redundant comments according to the situation.
insert image description here
After completion, we continue to save and exit (you can follow the previous prompts)
insert image description here
3 Check the record again (command: git log)
insert image description here
4 Force push to remote (command: git push -f)

Tip: Since I created a new branch by myself, I have not established a connection with the remote end, so I need to execute the git push -f --set-upstream origin gongneng command. You only need to execute the git push -f command at the beginning of the company

insert image description here
Now we have pressed multiple points into one point on our own function branch (multiple branches are combined into one branch), now we only need to cherry-pick this point to our pre-release branch.

Guess you like

Origin blog.csdn.net/qq_21237549/article/details/131406521