[Git01] Pro git Chapter 3 branch Reading Notes

Source: Internet
Author: User
Tags git workflow using git version control system
[Git] The Branch Model of the branch git is called the "killer feature" because it distinguishes git from the version control system family. What's special about git? Git branch is incredibly lightweight. Its new operations can be completed almost instantly, and switching between different branches is almost as fast. Unlike many other version control systems, git encourages frequent use of branches and mergers in workflows, even if it is performed many times in a day. After understanding the concept of the branch and using it skillfully, you will realize why git is such a powerful and unique tool and truly change your development method. Question1: How does git store data?
Git does not store file differences or changes, but just a series of file snapshots.
The branch in git is essentially a variable pointer to a commit object. Git uses master as the default branch name. After several commits, you actually have a master branch pointing to the last submitted object. It will automatically move forward each commit. Question2: How does git create a new branch?
# Create a new branch pointer.
$ Git branch Testing
Question3: How does git know on which branch you are currently working on?
It stores a special pointer named head. Note that it is very different from the head concept in many other version control systems you are familiar. In git, It is a pointer to the local branch you are working on. Running the GIT branch command only creates a new branch, but does not automatically switch to the Branch. Therefore, in this example, we still work in the master branch (see Figure 3.5 ).

To switch to another branch, run the GIT checkout command.
$ git checkout testing
In this case, the operated file is in testing branch. You can switch between testing and master at will and change it. Then your structure will be divided into two branches: This is called a branch, which is too apt: Because the branch in git is actually only a string containing the object checksum (40 characters long SHA-1 string) so it is very cheap to create and destroy a branch. To put it bluntly, creating a new branch is as simple as writing 41 bytes (plus a line break) to a file, and of course it will be very fast. Next, let's take a look at why we should use branches frequently? In actual work, such a workflow is also used:
1. Develop a website. 2. Create a branch to meet a new requirement. 3. Work on this branch. Suppose that you suddenly receive a call saying that there is a serious problem that needs urgent repair, you can handle it in the following way: 1. return to the branch that has been released to the production server. 2. Create a new branch for this urgent patch. 3. After the test is passed, merge the patch branches and push them to the production server. 4. Switch to the branch that previously implemented the new requirements to continue working.
The central idea is: you can switch on branchs at will, so one branch will do one thing (fix a bug), and each branch will be independent from each other, this will be a very clear workflow. PS: each new branch is directed by the current pointer.
$ Git checkout-B iss53switched to a new branch "iss53" # equivalent to: $ git branch iss53 $ git checkout iss53
After testing and fixing the bug, merge it into the master branch and publish it to the production server. Use the GIT merge command to merge:
$ git checkout master$ git merge hotfix
The merged hotfix is useless.
$ git branch -d hotfixDeleted branch hotfix (3a0874c).
If the merge conflict occurs:
$ git merge iss53Auto-merging index.htmlCONFLICT (content): Merge conflict in index.htmlAutomatic merge failed; fix conflicts and then commit the result.
Git is merged but not submitted. It stops waiting for you to resolve the conflict. To see which files conflict with each other during the merge, you can use git status to check whether all the conflicts have been resolved. That is, you can use git commit to complete the merge submission. The submitted records are similar to the following:
Merge branch ‘iss53‘Conflicts:index.html## It looks like you may be committing a MERGE.# If this is not correct, please remove the file# .git/MERGE_HEAD# and try again.#
If you want to make it easier for the person who will check the merger in the future, you can modify the information and provide more merging details. For example, what changes have you made and the reasons for doing so. Sometimes the reasons for the ruling conflict are not direct or obvious, and it is necessary to add annotations. Branch management:View branch status
$git branchissue53*mastertesting

 

Note that the * character before the master branch indicates the current branch. That is to say, if an update is submitted, the master branch will move forward with the development progress. To view the last commit information of each branch, run
$ git branch -v:
You can use the -- merge and -- no-merged options (GIT 1.5.6 or later) to filter out the branches that you have (or have not) merged with the current branch from this list ). For example, git branch-merge can be used to check which branches have been merged into the current branch. Generally, branches that do not have * in the list can be deleted using git branch-D. The reason is simple. Since the work they contain has been integrated into other branches, deleting them will not cause any loss. You can also use git Branch -- no-merged to view jobs that have not been merged:
$ git branch --no-mergedtesting
We will see the remaining branches that have not been merged. Because it also contains unmerged jobs, use git branch-D to delete them.
In addition to this branch, failure occurs:
$ git branch -d testingerror: The branch ‘testing‘ is not an ancestor of your current HEAD.
However, if you firmly believe that you want to delete it, you can use the delete option in uppercase-D to force execution, for example
$ git branch -D testing

Next section: Let's take a look at the basic Git workflow types, detailed practices and advantages and disadvantages :)

 

 

Too! Yes! Love! Now! When you moved, you turned to see if there was any space next to it !!

[Git01] Pro git Chapter 3 branch Reading Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.