1. Merging between branches
1) Direct Merge: Combine the historical trajectories on the two branches (that is, all changes are merged)
[Email protected]7817:~/mygit$ vim merge.txt[email protected]-ms-7817:~/mygit$ git St g# on branch thrid# untracked files:# ( use"git add <file>, ... ."To includeinchWhat'll be committed) # # merge.txtnothing added to commit and untracked files present ( use"git add"to track ) [Email protected]-ms-7817:~/mygit$ git Add. [Email protected]-ms-7817: ~/mygit$ git commit-m"Merge"[thrid 6436f0b] Merge1Files changed,1Insertions (+),0Deletions (-) Create mode100644Merge.txt[email protected]-ms-7817: ~/mygit$ git log-1Commit 6436f0b6bbe0da18ce65e90dd7ea90cf4008bbe3author:zhangshuli<[email protected]>Date:sat Feb - A:Panax Notoginseng: - -+0000Merge[email protected]-ms-7817:~/mygit$ git checkout parent switched to branch'Parent'[email protected]-ms-7817:~/mygit$ git merge thrid merge made by recursive. Merge.txt|1+MySite-1.0.Tar. gz | Bin0-501bytes MySite-1.0.Zip| Bin0-501bytes3Files changed,1Insertions (+),0Deletions (-) Create mode100644merge.txt Create mode100644mysite-1.0.Tar. GZ Create mode100644mysite-1.0.Zip[email protected]-ms-7817: ~/mygit$ git BR-av* Parent 44d288e Merge Branch'Thrid'into parent son 3a1cbb4 CCC add thrid 6436f0b merge[email protected]-ms-7817: ~/mygit$lsaaa.txt bbb.txt ccc.txt ddd.txt merge.txt mysite-1.0.Tar. GZ mysite-1.0.Zip[email protected]-ms-7817: ~/mygit$ git log-1Commit 44D288E4316E47AC9B6E3EE6A4152ACEFF5D17CEMERGE:E2E09C4 6436f0bauthor:zhangshuli<[email protected]>Date:sat Feb - A: -: - -+0000Merge Branch'Thrid'into Parent[email protected]-ms-7817: ~/mygit$
2) Press-Fit Merge: One branch and several commits merged into one, then merged onto another branch (squash)
[Email protected]7817:~/mygit$ git branch parent son*Third[email protected]-ms-7817: ~/mygit$lsaaa.txt Bbb.txt[email protected]-ms-7817:~/mygit$ vim ccc.txt[email protected]-ms-7817:~/mygit$ vim ddd.txt[email protected]-ms-7817:~/mygit$ git St # on branch third# untracked files:# ( use"git add <file>, ... ."To includeinchWhat'll be committed) # # ccc.txt# Ddd.txtnothing added to commit and untracked files present ( use"git add"to track ) [Email protected]-ms-7817:~/mygit$ git add ccc.txt[email protected]-ms-7817: ~/mygit$ git commit-m"Commit Ccc.txt"[Third 6a74382] Commit ccc.txt1Files changed,1Insertions (+),0Deletions (-) Create mode100644Ccc.txt[email protected]-ms-7817: ~/mygit$ git log-1Commit 6a74382c9c481515cd70136ce3212ace7aa1c50eauthor:zhangshuli<[email protected]>Date:sat Feb - -: ,: - -+0000commit Ccc.txt[email protected]-ms-7817:~/mygit$ git St # on branch third# untracked files:# ( use"git add <file>, ... ."To includeinchWhat'll be committed) # # ddd.txtnothing added to commit and untracked files present ( use"git add"to track ) [Email protected]-ms-7817:~/mygit$ git Add. [Email protected]-ms-7817: ~/mygit$ git commit-m"Commit DDD"[Third 618011f] Commit DDD1Files changed,1Insertions (+),0Deletions (-) Create mode100644Ddd.txt[email protected]-ms-7817: ~/mygit$ git log-1Commit 618011fc23e6fe8108e830e2812a298ad217d0cbauthor:zhangshuli<[email protected]>Date:sat Feb - -: ,: $ -+0000commit Ddd[email protected]-ms-7817:~/mygit$ git checkout parent switched to branch'Parent'[email protected]-ms-7817: ~/mygit$ git Merge--Squash Third Updating 2A30FCA. 618011fFast-Forwardsquash Commit--Not updating HEAD ccc.txt|1+Ddd.txt|1+2Files changed,2Insertions (+),0Deletions (-) Create mode100644ccc.txt Create mode100644Ddd.txt[email protected]-ms-7817:~/mygit$ git St # on branch parent# changes to being committed:# ( use"git reset HEAD <file>"to Unstage) # # Newfile: ccc.txt# Newfile: Ddd.txt#[email protected]-ms-7817: ~/mygit$ git commit-m"Yahe"[Parent 02906A1] Yahe2Files changed,2Insertions (+),0Deletions (-) Create mode100644ccc.txt Create mode100644Ddd.txt[email protected]-ms-7817: ~/mygit$ git log-1Commit 02906a15dc15be5fefd5e41dcd3977bb2f762cffauthor:zhangshuli<[email protected]>Date:sat Feb - -:Ten: $ -+0000Yahe[email protected]-ms-7817: ~/mygit$
As we can see from the above, the so-called compaction branch is actually moving the state of the other branch to the other branch, except that it is not a merge, but instead transforms the commit into a change store to the target branch cache, allowing you to handle it uniformly
3) Pick Merge (cherry-picking): Merge a Commit
[Email protected]7817: ~/mygit$ git log-1Commit 068698c5c848ded943f3454691f420136a2930eeauthor:zhangshuli<[email protected]>Date:sat Feb - -: -: - -+0000Cherry-Pick[email protected]-ms-7817:~/mygit$ git checkout parent switched to branch'Parent'[email protected]-ms-7817: ~/mygit$ git cherry-pick 068698c5c848ded943f3454691f420136a2930eefinished One cherry-pick. [Parent 1c33f51] Cherry-Pick1Files changed,1Insertions (+),0Deletions (-) [email protected]-ms-7817: ~/mygit$lsaaa.txt bbb.txt ccc.txt ddd.txt[email protected]-ms-7817: ~/mygit$ git log-1Commit 1c33f513af17f21dd157522b98a2027047d599c3author:zhangshuli<[email protected]>Date:sat Feb - -: -: - -+0000Cherry-Pick[email protected]-ms-7817: ~/mygit$lsaaa.txt bbb.txt ccc.txt ddd.txt[email protected]-ms-7817:~/mygit$ vim aaa.txt [email protected]-ms-7817: ~/mygit$
The command it uses is Cherry-pick and the parameter is not branch but the node number.
If you want to cherry-pick a commit, but do not submit it immediately on this branch, you can use parameter-N, which works just like the compression merge effect.
[Email protected] 7817: ~/mygit$ git cherry-pick-n 068698c5c848ded943f3454691f420136a2930eefinished one cherry- Pick. [Email protected] -ms-7817: ~/mygit$ git St # on branch parent# changes to be committed:# "git reset HEAD <file>, ..... " to Unstage) # # modified: aaa.txt#[email protected]-ms-7817: ~/mygit$ git commit
2. Handling of Merge branch conflicts
Just execute the command git mergetool, it will automatically open a merge tool
Summary of the use of Worktools-git tools (4)