3. Branching in Git 3.1 The structure of GIT metadata when commit commits
Shows git at commit, the contents of the 5 Blob objects, and the relationship between each object, three files, a tree, and a commit object.
Shows the relationship between each commit and the last commit when the file is modified and submitted.
3.2 The concept of branching in Git
You can see that the branch is actually a pointer, just like master, and points to the current commit object.
3.3 How do you distinguish which branch you are currently on?
The head pointer is an implied pointer that points to which branch you are currently in.
To switch branches:
$ git checkout Testing
3.4 Commit on a branch
When a commit is made on a branch, the head pointer moves forward along with the branch and points to the new commit object.
3.5 Branches of different flows
When different branches are operated, different sub-tributaries are generated.
3.6 New and merged branches
Background application Environment:
1. Develop a website.
2. Create a branch to implement a new requirement.
3. Work on this branch.
Suppose at this point that you suddenly receive a call saying that there is a serious problem that needs urgent repair, you can do it in the following way:
1. Return to the branch that was previously published on the production server.
2. Establish a new branch for this emergency repair and fix the problem in it.
3. After passing the test, go back to the branch where the production server is located, merge the patch branches in, and then push to the production server.
4. Switch to the branch that previously implemented the new requirement and continue working.
3.7 Merge Operation instances
//Create a Project working directory[Ro[email protected] git]#mkdirProjectone[[email protected] git]# CD Projectone/[[email protected] projectone]# git initinitialized empty git repositoryinch/root/git/projectone/.git/[[email protected] projectone]# git status# on branch master## Initial commit#nothing to commit (create/copy Files and use"git add"to track ) [Email protected] projectone]#TouchMaster_file1.txt[[email protected] projectone]#TouchMaster_file2.txt[[email protected] projectone]#TouchMaster_file3.txt[[email protected] projectone]#TouchModule1_file1.txt[[email protected] projectone]#TouchModule1_file2.txt[[email protected] projectone]#Touchmodule1_file3.txt[[email protected] projectone]# git Add. [[email protected] projectone]# git commit-M"Initial Project"[Master (Root-commit) 475feb1] Initial project0Files changed,0Insertions (+),0Deletions (-) Create mode100644master_file1.txt Create mode100644master_file2.txt Create mode100644master_file3.txt Create mode100644module1_file1.txt Create mode100644module1_file2.txt Create mode100644Module1_file3.txt//create two branches Module1 and Module2[[email protected] projectone]# git branch module1[[email protected] projectone]# git checkout module1switched to Bran CH'Module1'//Create a branch at the same time and switch to the corresponding branch[[email protected] projectone]# git checkout-b module2switched to a new branch'Module2'[[email protected] projectone]# git branch master Module1*module2[[email protected] projectone]# git checkout module1switched to branch'Module1'[[email protected] projectone]# git branch master*Module1 Module2//modifying files on the Module1 branch[Email protected] projectone]#VImodule1_file1.txt [[email protected] projectone]# git commit-M"Module1 v1.0"# on Branch module1# Changed and not updated:# ( use"git add <file>, ... ."To update what'll be committed) # ( use"git checkout--<file>, ... ."To discard changesinchworking directory) # # Modified:module1_file1.txt#no changes added to commit ( use"git add"and/or"git commit-a") [[email protected] projectone]# git commit-a-m"Module1 v1.0"[Module1 8541DFB] Module1 v1.0 1Files changed,4Insertions (+),0Deletions (-) [[email protected] projectone]# git status# on branch module1nothing to commit (working directory clean) [email prot ected] projectone]# git branch master*Module1 module2[[email protected] projectone]# git checkout masterswitched to branch'Master'[[email protected] projectone]# git status# on branch masternothing to commit (working directory clean)//using log, you can see that the pointers for master and Module1 differ[[email protected] projectone]# git checkout module1[[email protected] projectone]# git log--pretty=oneline8541dfb34bc67a1d37076b0154de94f83b73d69a Module1 v1.0475feb1c57e9ea1e679e68ed7ef9ab2491f64308 initial project[[email protected] projectone]# git checkout masterswitched to Branch'Master'[[email protected] projectone]# git log--pretty=oneline475feb1c57e9ea1e679e68ed7ef9ab2491f64308 initial project[[email protected] projectone]# git checkout module1switched to Branch'Module1'[[email protected] projectone]# git log--pretty=oneline8541dfb34bc67a1d37076b0154de94f83b73d69a Module1 v1.0475feb1c57e9ea1e679e68ed7ef9ab2491f64308 initial project[[email protected] projectone]#VImodule1_file2.txt [[email protected] projectone]# git commit-a-m"file2 done ...."[Module1 44a5266] File2 Done.... 1Files changed,5Insertions (+),0Deletions (-) [[email protected] projectone]# git log--pretty=oneline44a526677cdb3b6a95b8f47e35dc575e350c2f73 file2 Done.... 8541dfb34bc67a1d37076b0154de94f83b73d69a Module1 v1.0475feb1c57e9ea1e679e68ed7ef9ab2491f64308 Initial project [[email protected] projectone]# git branch master*Module1 module2[[email protected] projectone]# git checkout master [[email protected] projectone]# git log--pretty=oneline475feb1c57e9ea1e679e68ed7ef9ab2491f64308 Initial Project//merging branches, there is a fast-forward, which shows that the merge is down a line. [[email protected] projectone]# git merge module1updating 475feb1. 44a5266fast-forward Module1_file1.txt|4++++Module1_file2.txt|5+++++2Files changed,9Insertions (+),0Deletions (-) [[email protected] projectone]#Catmodule1_file2.txt module2_file_ ..... Done... [[email protected] projectone]# git log--pretty=oneline44a526677cdb3b6a95b8f47e35dc575e350c2f73 file2 Done.... 8541dfb34bc67a1d37076b0154de94f83b73d69a Module1 v1.0475feb1c57e9ea1e679e68ed7ef9ab2491f64308 initial project[[email protected] projectone]# git branch*Master Module1 module2
3.8 Deleting a branch
$ git branch-d Hotfix
3.9 Nonlinear Merging
, Master has already made an update, and the branch iss53 has been developed from C2 to C5, at this point, if Master merges, it will need to C2 C4 C5 The three-party merge, the merged results as shown, then you can delete the ISS53 branch.
3.10 Conflicts when merging
At this time through the GIT status can see the unmerged state of the files, to these files, manually resolve the conflict, and then commit.
Linux------Git-3