This is the third day of my participation in Gwen Challenge

preface

As is known to all, a few days ago to take an examination of English level 6 can’t still use English for a few days to review the (damn six levels, it’s hard to ~), and then drag more ha ha ha, this time for a branch of practice is to consolidate what they have learned knowledge, please donate said began to cough up ~ to think before you drill a few small problems.

  • Switch branches what areas change? 1. The contents of the HEAD file will change because the HEAD file contains the branch that is currently in use. 2. The staging area changes because switching branches means that you need to develop a new feature in one version of the project, so the staging area also changes. 3. The contents of the workspace have changed. To switch branches is to do version shuttle.
  • What if the workspace has just created a new file, or created a file that was added to staging but not committed, and then switched branches? (Directly to the above illustration ~)

Let’s look at the second scenario.

As we can see from the above, both cases can be switched, which may cause problems in future development. For example, if I want to implement a function in the Jc branch and I return the master branch before committing it, the master branch will have too many files, which will cause a lot of errors. If I have committed four files in the staging area on the Jc branch, will there still be four.txt in the staging area after switching to the master branch? The answer is obviously no, since it is submitted it belongs to the Jc branch.

  • Can we switch branches if we modify the four file already committed on the Jc branch? Answer you guess ~ that certainly does not let switch ha ha

Through the above analysis, we later switch branches must be certain to pay attention to, or a miss into eternal hate ~ not much to say directly into today’s theme!

First, branch actual combat

Content: Let’s say you’re lighting a light, and you want to display the light switch on the display screen, so you open a new branch to do this. While modifying the code, you suddenly realize that there is something wrong with the old (master branch) code that needs to be fixed. Then, after creating a branch and fixing the code, merge the change branches, push the changes to the online branch, and finally go back to the original branch to continue working. Go straight to the picture above

To this is a very simple actual combat drill, do not know that we did not understand the relationship did not understand you can draw a picture, so it is very easy ~~

Conclusion: From the above we can conclude that the essence of the branch is a mutable pointer to the submitted object. More specifically, the branch is a mutable pointer to the submitted object. The branch doesn’t move by itself but the HEAD pointer moves forward with the branch.

Second, the end

So far Git branch function simple actual combat exercise is completed, if you feel useful can point a praise oh! I will continue to update, if there are any mistakes please point out, thank you for your audience master.

To get a PDF of the above content, go to GitHub and download it.

Address: Git study notes area

— — — — — a romantic