GIT 分支新建与合并

1. 分支新建与合并

1.1. 分支的使用场景

1.开发某个程序。
2.实现新的需求,创建一个分支(function)。
3.在这个分支上展开工作。
6.紧急电话有个项目要特殊版本。
7.切换到你的线上分支。也是主分支(master)
8.创建新的分支,并在这个分支上修复BUG 。(BUG 分支)
9.测试后切换回主分支,合并这个修补分支,最后提交到主分支(master 分支)
10.切换最初的分支(function)继续工作。

1.2. 实际操作

git co -b iss53

等于

git br isss53
git co iss53

![](_v_images/20181115120535140_28561.png =480x)

$ vim index.html
$ git commit -a -m 'added a new footer [issue 53]'

![](_v_images/20181115120615276_2710.png =480x)

git co master
git co -b hotfix
$ git checkout master
git merge hotfix
git br -d hotfix
git merge iss53

![](_v_images/20181115121027422_28557.png =560x)

![](_v_images/20181115121047306_9924.png =560x)

注意此处做了一次三方合并

git br -d iss53

2. 分支冲突合并

$ git merge bugfix
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

aming@aming-PC MINGW64 /d/scripts/test (master|MERGING)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 5 commits.
  (use "git push" to publish your local commits)
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

aming@aming-PC MINGW64 /d/scripts/test (master|MERGING)