Eclipse egit (on branch management)

This chapter is more important. It tells about the power of Git than svn. Directly reprint the text of Mr. Liao Xuefeng to better understand what branch is and why branch git is better than svn.


What is the use of branches in practice? Suppose you are going to develop a new feature, but it takes two weeks to complete. You wrote 50% of the code in the first week. If you submit it immediately, the incomplete code base will cause others to be unable to work because the code has not been written yet. If you wait for the code to be fully written and then submit it again, there is a huge risk of losing your daily progress. 


Now that you have branches, you don't have to be afraid. You created a branch that belongs to you, others can't see it, and you continue to work normally on the original branch, while you work on your own branch, submit it if you want to, until the development is completed, and then merge it into On the original branch, in this way, it is both safe and does not affect the work of others. 


Other version control systems such as SVN have branch management, but after using them, you will find that these version control systems are slower than a snail to create and switch branches, which is simply unbearable. As a result, the branch function has become a decoration, and everyone does not go. use. 


But Git's branch is different, whether creating, switching and deleting branches, Git can do it in 1 second! Whether your repository is 1 file or 10,000 files. 

Let's see how to create a branch in eclipse and use it in practice.

In previous versions, we know that git has a default timeline for each project, which is the master branch. For each commit, Git string them together into a timeline, and then there is a head pointer, and Git uses master to point to the latest The commit, and then use HEAD to point to master, you can determine the current branch and the commit point of the current branch.

First, we create the dev branch, then switch to the dev branch:

In git repositories, click on the branches of the project, -> right-click switch to -> new branch, and head has pointed to the "dev" branch by default, each of your commits in the future will be operated on 'dev', which has been followed by ' master' branch is irrelevant. 
write picture description here

Now the history box looks like this: 
write picture description here

We add a method dev() to the demo. Java file, and then commit (commit), the 
head pointer no longer points to the master branch, but follows the 'dev' branch. 
write picture description here

When we switch back to the latest commit point on the 'master' branch (checkout on the master branch), the dev() method is gone: 
write picture description here

Then if we finish the work on the dev branch, how do we merge it into the master branch?

1. Switch back to the 'master' branch on the git repository interface (right-click master->checkout) 
write picture description here

2. Then right-click master-"merge.., pay attention to the second option of fast forward options, you can see the details of the branch merge in the History box, and you can see that the merge has been done. 
write picture description here

3. Select the branch you need to merge into the 'master' branch in the Local folder, here of course select the 'dev' branch. Then click merge. 
write picture description here

As you can see from the history box above, head now points back to the 'master' branch, and the contents of the 'dev' branch have been merged.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324602072&siteId=291194637