There is often a common problem when using git development. Multiple commits need to be merged into a full commit commit.
Let's start with the first one. Merge multiple commits into a complete commit
I'm going to start out with a functional branch based on the develop main branch (everyone and each company are different about the branch management, and there's no need to be too tangled here.) )。 The develop here is to develop the main branch, all the development function code need to return to this develop branch.
Git branch-a–vv
650) this.width=650; "title=" 1 "style=" border-right-width:0px;background-image:none;border-bottom-width:0px; padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px; "border=" 0 "alt=" 1 "src=" http:// S3.51cto.com/wyfs02/m02/89/35/wkiol1gmvtgtpg6aaaazm88qoh4105.png "width=" "height="/>
The Develop_fixbug_imageprint branch is the development Branch I pulled out based on the remote develop branch, and I'll fix some bugs based on this branch. We look at develop, Develop_fixbug_imageprint commit log respectively.
git checkout Develop
git log
650) this.width=650; "title=" 2 "style=" border-right-width:0px;background-image:none;border-bottom-width:0px; padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px; "border=" 0 "alt=" 2 "src=" http:// S3.51cto.com/wyfs02/m00/89/36/wkiol1gmvtgjcgkqaabpthhuody599.png "width=" 583 "height=" 317 "/>
git checkout Develop_fixbug_imageprint
git log
650) this.width=650; "title=" 3 "style=" border-right-width:0px;background-image:none;border-bottom-width:0px; padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px; "border=" 0 "alt=" 3 "src=" http:// S3.51cto.com/wyfs02/m01/89/38/wkiom1gmvtlqsohuaabufcyqohu952.png "width=" 720 "height=" 315 "/>
Develop_fixbug_imageprint's commit log is identical to the Devleop commit log. We now switch to develop_fixbug_imageprint for some action.
Add a 1.txt file, and then git Add. , git commit–m ' Add 1.txt '.
Add a 2.txt file, and then git Add. , git commit–m ' Add 2.txt '.
650) this.width=650; "title=" 4 "style=" border-right-width:0px;background-image:none;border-bottom-width:0px; padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px; "border=" 0 "alt=" 4 "src=" http:// S3.51cto.com/wyfs02/m01/89/38/wkiom1gmvtkamjyjaacdmys9lys675.png "width=" 723 "height=" 502 "/>
Now there are two commits in the Develop_fixbug_imageprint branch. These two commits are for the two commits that are made to fix the current bug. Now we want to merge the main develop branches of the code. You can not submit these two commits directly, here is only two commits, but the general project development cycle of two weeks, you have at least more than 10 commits. It is difficult to manage and track after submission. (I've done this before, and now I find it's not good to track management.) )
So how do we complete this merge commit, we need to use the git rebase command.
Let's start by explaining git rebase. You can actually interpret it as "reset baseline" and reset your current branch to the start point. This is the time to know the difference between your current branch and the branch you need to compare.
For example, if the Develop_fixbug_imageprint branch is from the develop branch, then we are basically developing from the start of test commit and are now in Develop_fixbug_ There are two commits on the ImagePrint branch, we need to find a benchmark, which is what git needs to find the commmit you submitted later, with a general reference.
git reabse–i Develop
650) this.width=650; "title=" 5 "style=" border-right-width:0px;background-image:none;border-bottom-width:0px; padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px; "border=" 0 "alt=" 5 "src=" http:// S3.51cto.com/wyfs02/m00/89/38/wkiom1gmvtohxqnhaacspos5g4u300.png "width=" 707 "height=" 377 "/>
Git rebase immediately know the difference between develop and develop_fixbug_imageprint. Because we are based on the develop setting rebase. Git rebase–i, where "-I" refers to interactive mode. This means you can intervene in the process of rebase this transaction, including setting a commit message, pausing a commit, and so on.
Here we ask that it is simple to merge the previous commit and reset the commit message.
We set the second "pick 657a291 add 2.txt" to "s 657a291 add 2.txt" Here s is shorthand for the squash command.
650) this.width=650; "title=" 6 "style=" border-right-width:0px;background-image:none;border-bottom-width:0px; padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px; "border=" 0 "alt=" 6 "src=" http:// S3.51cto.com/wyfs02/m01/89/38/wkiom1gmvtsbdqe8aabh2pkzoa4477.png "width=" 780 "height=" 444 "/>
A temporary file pops up, with two lines of commit message on top. We have modified this overall commit message.
650) this.width=650; "title=" 7 "style=" border-right-width:0px;background-image:none;border-bottom-width:0px; padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px; "border=" 0 "alt=" 7 "src=" http:// S3.51cto.com/wyfs02/m01/89/36/wkiol1gmvttxqjmhaabkmishfg4593.png "width=" 734 "height=" 225 "/>
Delete the previous two message (ESC DD), set the message for overall, and then save the exit. (ESC Wq)
650) this.width=650; "title=" 8 "style=" border-right-width:0px;background-image:none;border-bottom-width:0px; padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px; "border=" 0 "alt=" 8 "src=" http:// S3.51cto.com/wyfs02/m02/89/36/wkiol1gmvttyhjmdaaa2d48qxu0997.png "width=" 828 "height=" 148 "/>
Let's check the next log. git log
650) this.width=650; "title=" 9 "style=" border-right-width:0px;background-image:none;border-bottom-width:0px; padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px; "border=" 0 "alt=" 9 "src=" http:// S3.51cto.com/wyfs02/m02/89/38/wkiom1gmvtxazgp-aabrgq_ztto758.png "width=" 719 "height=" 411 "/>
Is there no previous two commits.
The principle is simple: rebase needs to set the baseline of your current branch based on a branch, which is the start timeline of the current branch moving backwards to the last face of the newest trace branch, so that your current branch is the newest trace branch. The operations here are based on file transactions, so you don't have to be afraid that intermediate failures can affect file consistency. In the middle of the process you can cancel the rebase transaction at any time. Git rebase–abort
In the Git rebase–i interactive mode, you can do a lot of things, you can set the edit commit content, you can let him pause the commit operation. Wait a minute.
This article from the "humble if foolish, thirst for knowledge" blog, please be sure to keep this source http://wangqingpei557.blog.51cto.com/1009349/1864806
Talk about Git rebase-i