Git in Mac simple and practical (6)---branch management policy

Source: Internet
Author: User

今天我来介绍下Git,Git是一款免费、开源的分布式版本控制系统。我们在上一个学习了Git分支冲突管理。这一章,我们要学习Git的Fast-forward模式、保存恢复现场  、测试的feature分支。

Git in Mac simple and practical (1)-git basic commands (1)
Git in Mac simple and Practical (2)-git basic commands (2)
Git in Mac Simple and Practical (3)-github remote repository
Simple and practical Git in Mac (4)-Branch branch management
Git in Mac Simple and practical (5)-git Branch conflict Management

1. Fast forward Mode
对于我们上一章学习merge命令,其实是使用Fast-forward模式,合并方式是“快进模式”。我们要学习禁用Fast-forward模式:    如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的commit,这样,从分支历史上就可以看出分支信息。

Let's do some real-–no-ff git merge:

First we create a branch called dev: mbp:git qiuyu$ git checkout-b dev switch to a new branch ' dev ' to modify git.txt and submit a new commit:git is OK.    Git is nice.    Change Branch.    Using Master.    Using Branch1.    The latest.    Test no fast-forward. Mbp:git qiuyu$ git add git.txt mbp:git qiuyu$ git commit-m "no fast-forward" [Dev d60705f] no fast-forward 1 fi Le changed, 1 insertion (+), 1 deletion (-) Now, we switch back to master:MBP:git qiuyu$ git checkout master switch to branch ' master ' on your branch with Travel Branch ' Origin/master ' consistent. To prepare to merge the Dev branch, note the--NO-FF parameter, which disables fast forward:MBP:git qiuyu$ git merge--no-ff-m "merge with No-ff" dev merge made by th    E ' recursive ' strategy. Git.txt | 2 +-1 file changed, 1 insertion (+), 1 deletion (-) after merging, we use git log to see the branching history: Mbp:git qiuyu$ git log--graph--pretty=one Line--abbrev-commit * 03d3111 merge with No-ff |\ | * d60705f No Fast-forward |/* 33605db the Lateset |\ | * b00c593 Branch1 * | 89519de Master |/* D2BA8F0 Branch Test * E5798F6 THe third release * f49806e the second release * 4644630 the first release 

First, the master branch generally commits only, not the work.

So where do you work? Work is done on the Dev branch, the work is finished, and the Dev branch is merged to Master and released in the Master branch.

You and your co-workers work on the Dev branch, and everyone has their own branch, and it's time to merge on the Dev branch.

2. Save Recovery site

When there is a bug we need to modify, you can create a branch to fix it
However, the work currently being done on Dev has not yet been submitted
Git also provides a stash function that can "store" the current work site, and then continue to work after resuming the site later

Modify Git.txt git is ok first.    Git is nice.    Change Branch.    Using Master.    Using Branch1.    The latest.    Test no fast-forward. Test git stash.  Mbp:git qiuyu$ git status is located in branch Master your branch leading ' origin/master ' a total of 2 commits. (using "Git push" to publish your local submission) has not yet been staged for submission of changes: (using "git add < file; ..." Update the content to be submitted) (using "Git checkout-< file; ..."  Discard workspace changes) Modify: Git.txt save live via git stash: mbp:git qiuyu$ git stashsaved working directory and index state WIP on master: 03d3111 Merge with No-ffhead now located in 03d3111 merge with No-ffmbp:git qiuyu$ git status located in branch Master your branch leading ' Origin/master ' Total 2  A commit. (use "Git push" to publish your local commits) we create a branch below to modify and commit: Mbp:git qiuyu$ git checkout-b debug01 switch to a new branch ' DEBUG01 ' Mbp:git Qiuy u$ git add git.txt mbp:git qiuyu$ git commit-m "debug01" [debug01 cfe4639] debug01 1 file changed, 1 insertion (      +) We switch to Master branch and delete debug01:MBP:git qiuyu$ git checkout master switch to branch ' master ' your branch leading ' origin/master ' a total of 2 submissions. (use "Git push" to publish your local commits) Mbp:git qiuyu$ git Merge--no-ff-m "debug01" debug01 merge made by the ' recursive ' strategy. Git.txt | 1 + 1 file changed, 1 insertion (+) mbp:git qiuyu$ git branch-d debug01 deleted branch DEBUG01 (formerly cfe4639).  Work site via git stash List command see: mbp:git qiuyu$ git stash list [email protected]{0}: WIP on master:03d3111 merge with NO-FF work site recovery: One is to use git stash apply recovery, but after recovery, stash content is not deleted, you need to use git stash drop to delete, the other way is to use git stash pop, restore the stash content also deleted: MBP: git qiuyu$ git stash list[email protected]{0}: WIP on master:03d3111 merge with No-ffmbp:git qiuyu$ git stash pop auto-fit and Git.txt conflict (content): Merge conflicts can be resolved by eliminating the conflict before git.txt.
3, the feature branch of the test

If you want to add an experiment code to the current branch and don't want to mess with master,
Each time a new feature is added, it is best to create a new branch, develop it on top, complete, merge, and finally delete the branch.

创建一个分支branch1:MBP:git qiuyu$ git checkout -b branch1切换到一个新分支 ‘branch1‘创建一个test.c的文件,进行提交:MBP:git qiuyu$ vi test.cMBP:git qiuyu$ git add test.cMBP:git qiuyu$ git status位于分支 branch1要提交的变更:  (使用 "git reset HEAD <文件>..." 撤出暂存区)    新文件:   test.cMBP:git qiuyu$ git commit -m "add test"[branch1 004cc16] add test 1 file changed, 1 insertion(+) create mode 100644 test.c这时候测试分支需要丢弃,则需要使用git branch -D 命令:首先切回master:MBP:git qiuyu$ git checkout master切换到分支 ‘master‘您的分支与上游分支 ‘origin/master‘ 一致。对branch1进行删除:MBP:git qiuyu$ git branch -d branch1error: 分支 ‘branch1‘ 没有完全合并。如果您确认要删除它,执行 ‘git branch -D branch1‘。MBP:git qiuyu$ git branch -D branch1已删除分支 branch1(曾为 004cc16)。

Git in Mac simple and practical (6)---branch management policy

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.