Git version 1.9.6
1. Create and delete branches
2. Create branches, merge branches, and delete branches
3. Create branch, git 3-way merge, and delete Branch
Git branch commands
Git branch # list the current number of branchgit Branch New-branch # generate a new branch (Name: New-branch). If not specified, the current branch/master will directly copy one copy. git Branch New-branch master # create a new branch (New-branch) by the master git Branch New-branch V1 # generate a new branch (New-branch) by TAG (V1) git branch-d New-branch # delete new-branchgit branch-d New-branch # force delete new-branchgit checkout-B New-branch test # generate new branch, and switch to new-branch # git branch-R related to remote repository # list all repository branchgit branch-A # list all branch
1. Create and delete branches
1.1 create Branch
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/C0/wKiom1RY0T7C2gAlAADpz6TH5dk752.jpg "Title =" c1.jpg "alt =" wkiom1ry0t7c2galaadpz6th5dk752.jpg "/>
1.2 switch to the new branch; testbranch
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/C0/wKiom1RY0XfifID4AADruGL_8RM633.jpg "Title =" c1.jpg "alt =" wkiom1ry0x0000id4aadrugl_8rm633.jpg "/>
Head changes during switchover
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/C0/wKioL1RY1YWT3l-iAADQDMzT36w651.jpg "Title =" c1.jpg "alt =" wKioL1RY1YWT3l-iAADQDMzT36w651.jpg "/>
That is to say, although the head points to testbranch after the switch, testbranch points to the last commit like the master;
The verification is as follows:
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/C0/wKiom1RY1Yqg05KEAAIVSl-xrac913.jpg "Title =" c1.jpg "alt =" wKiom1RY1Yqg05KEAAIVSl-xrac913.jpg "/>
Head after Switch
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/C0/wKiom1RY1emAU_44AACRF-arqfI612.jpg "Title =" c1.jpg "alt =" wKiom1RY1emAU_44AACRF-arqfI612.jpg "/>
1.3 switch back to master for verification and delete testbranch
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/C0/wKiom1RY1k3i7Ad5AADu_nBEIjg122.jpg "Title =" c1.jpg "alt =" wkiom1ry1k3i7ad5aadu_nbeijg122.jpg "/>
Delete testbranch, and the branch index file does not exist.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/4D/C0/wKioL1RY1v7SSZ5NAAD55K3MtIc226.jpg "Title =" c1.jpg "alt =" wkiol1ry1v7ssz5naad55k3mtic226.jpg "/>
2. Create branches, merge branches, and delete branches
2.1 view the final commit log of the current master; create the branch testbranch
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/C0/wKioL1RY3XXAWHsvAADj1jgTQIk649.jpg "Title =" c1.jpg "alt =" wkiol1ry3xxawhsvaadj1jgtqik649.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/4D/C0/wKioL1RY3bPS14RrAAE---nXga4698.jpg "Title =" c1.jpg "alt =" wKioL1RY3bPS14RrAAE---nXga4698.jpg "/>
2.2 modify the code in the current branch and run the commit command to view the current commit log;
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/C0/wKioL1RY3oHCSNYcAAKP7MWetac567.jpg "Title =" c1.jpg "alt =" wkiol1ry3ohcsnycaakp7mwetac567.jpg "/>
2.3 switch back to the master, view the commit log merge branch, view the commit log, delete the branch testbranch, and view the commit log;
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/C0/wKioL1RY3xPgb5kDAAC6Y4n7avA730.jpg "Title =" c1.jpg "alt =" wkiol1ry3xpgb5kdaac6y4n7ava730.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/C1/wKiom1RY3uKTOCIiAAEj93vrlDM777.jpg "Title =" c1.jpg "alt =" wkiom1ry3uktociiaaej93vrldm777.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/C0/wKioL1RY326hgGxnAADj9FYh530226.jpg "Title =" c1.jpg "alt =" wkiol1ry326hggxnaadj9fyh530226.jpg "/>
TIPS:
Why delete testbranch after merging?
In the master branch, the final index corresponding to it is last commit,
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/C0/wKioL1RY2aai00fqAABq3WnkmYI879.jpg "Title =" c1.jpg "alt =" wkiol1ry2aai00fqaabq3wnkmyi879.jpg "/>
In the testbranch branch, the final index corresponding to him is his new commit. We assume it is B;
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/C0/wKioL1RY2rexnfqPAACCNJuWzH0775.jpg "Title =" c1.jpg "alt =" wkiol1ry2rexnfqpaaccnjuwzh0775.jpg "/>
If we force Delete the branch testbranch from the master branch, the new commit of the testbranch branch will be invalid. Therefore, we need to merge testbranch first, delete it, And then index it after merging.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/C1/wKiom1RY2yqid7JQAADuGBVm2hk488.jpg "Title =" c1.jpg "alt =" wkiom1ry2yqid7jqaadugbvm2hk488.jpg "/>
It can be seen from the commit log above;
3. Create branch, git 3-way merge, and delete Branch
PS: The Branch is created above, and the code of the Branch is modified and submitted. What if the code of the Branch is modified and the code of the master is modified?
3.1 view the master branch commit log, create the testbranch branch, view the commit log, modify the code twice, and run the commit command to view the commit log;
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/C0/wKioL1RY5e7y4NW3AAC5OgADrZo846.jpg "Title =" c1.jpg "alt =" wkiol1ry5e7y4nw3aac5ogadrzo846.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/C1/wKiom1RY5b6T774lAACyRiwEl3I948.jpg "Title =" c1.jpg "alt =" wkiom1ry5b6t774laacyriwel3i948.jpg "/>
$ echo "print \"Test1\"" >> hello.pl$ git commit -am "test1"$ echo "print \"Test2\"" >> hello.pl$ git commit -am "test2"
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/4D/C1/wKiom1RY5qPR-DEpAACTQiFkCZ8843.jpg "Title =" c1.jpg "alt =" wKiom1RY5qPR-DEpAACTQiFkCZ8843.jpg "/>
3.2 switch to the master to view the commit log. modify the code and perform the commit operation. view the commit log;
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4D/C1/wKiom1RY5wvxRc2IAADW_O05l5k779.jpg "Title =" c1.jpg "alt =" wkiom1ry5wvxrc2iaadw_o05l5k779.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/C1/wKiom1RY5zvClbQPAAJ5FDeM_48127.jpg "Title =" c1.jpg "alt =" wkiom1ry5zvclbqpaaj5fdem_48127.jpg "/>
3.3 merge testbranch and delete testbranch
$ git merge Testbranch$ git branch -d TestbranchDeleted branch Testbranch (was ec4c4ba).
This article is from the "Big Brother" blog, please be sure to keep this source http://lansgg.blog.51cto.com/5675165/1571877
Git branch create Branch delete branch merge