(Git) Merge multiple commits

When using Git as version control, we may submit many temporary commits due to various reasons, and the stitching of these commits is the complete task. In order to avoid the confusion of version control caused by too many commits, we usually recommend merging these commits into one.

1, View the submission history, git log

First of all, you need to know which commits you want to merge. You can use the git log command to view the commit history. If the last 4 history is as follows:

commit 3ca6ec340edc66df13423f36f52919dfa3......

commit 1b4056686d1b494a5c86757f9eaed844......

commit 53f244ac8730d33b353bee3b24210b07......

commit 3a4226b4a0b6fa68783b07f1cee7b688.......

The history records are sorted by time, with the most recent ones at the top.

2, git rebase

There are two ways to merge 1-3

1. Count 3 versions from the HEAD version to the past

git rebase -i HEAD~3

2. Name the version number before the version to be merged

git rebase -i 3a4226b

Please note that this version of 3a4226b does not participate in the merger, it can be used as a coordinate

3. Select the submission to be merged

1. After executing the rebase command, a window will pop up, the first few lines are as follows:

pick 3ca6ec3   '注释**********'

pick 1b40566   '注释*********'

pick 53f244a   '注释**********'

2. Change pick to squash or s, then save and close the text editing window. After the modification, the text content is as follows:

pick 3ca6ec3   '注释**********'

s 1b40566   '注释*********'

s 53f244a   '注释**********'

3. Then save and exit. Git will compress the submission history. If there is a conflict, you need to modify it. Please pay attention to the modification and keep the latest history, otherwise our modification will be discarded. Remember to type the following command after modification:

git add .  

git rebase --continue  

If you want to give up this compression, execute the following command:

git rebase --abort  

4. If there is no conflict, or the conflict has been resolved, the following editing window will appear:

# This is a combination of 4 commits.  
#The first commit’s message is:  
注释......
# The 2nd commit’s message is:  
注释......
# The 3rd commit’s message is:  
注释......
# Please enter the commit message for your changes. Lines starting # with ‘#’ will be ignored, and an empty message aborts the commit.

5. Enter wq to save and launch, enter git log again to view the commit history information, you will find that the two commits have been merged.

You can also refer to other http://www.jianshu.com/p/964d...

Guess you like

Origin blog.csdn.net/weixin_44273311/article/details/107998741