当前位置: > Linux服务器 > Git >

GIT分支衍合实例

时间:2014-10-30 12:01来源:linux.it.net.cn 作者:it
Git的衍合原理是,在两个分支同时提交更新,在一个分支衍合另外一个分支,相当于那对方的补丁来更新自己,而被衍合的分支不发生改变。
 
[root@localhost wanyan]# vi rebase1
 
[root@localhost wanyan]# cat rebase1
 
first
 
[root@localhost wanyan]# vi rebase2
 
[root@localhost wanyan]# cat rebase2
 
1
 
[root@localhost wanyan]# git init
 
Initialized empty Git repository in /git/wanyan/.git/
 
[root@localhost wanyan]# git add .
 
[root@localhost wanyan]# git commit -m '1st commint'
 
[master (root-commit) 9e8b3cd] 1st commint
 
 2 files changed, 2 insertions(+), 0 deletions(-)
 
 create mode 100644 rebase1
 
 create mode 100644 rebase2
 
 [root@localhost wanyan]# git branch laji
 
[root@localhost wanyan]# git branch
 
  laji
 
* master
 
[root@localhost wanyan]# git checkout laji
 
Switched to branch 'laji'
 
[root@localhost wanyan]# vi rebase1
 
[root@localhost wanyan]# cat rebase1
 
first
 
two
 
[root@localhost wanyan]# git commit -a -m "laji"
 
[laji 065adde] laji
 
 1 files changed, 1 insertions(+), 0 deletions(-)
 
[root@localhost wanyan]# git checkout master
 
Switched to branch 'master'
 
[root@localhost wanyan]# vi rebase2
 
[root@localhost wanyan]# cat rebase2
 
 
[root@localhost wanyan]# git commit -a -m "master"
 
[master ce848ae] master
 
 1 files changed, 1 insertions(+), 0 deletions(-)
 
[root@localhost wanyan]# git branch
 
  laji
 
* master
 
[root@localhost wanyan]# git checkout laji
 
Switched to branch 'laji'
 
[root@localhost wanyan]# git branch
 
* laji
 
  master
 
[root@localhost wanyan]# git rebase master
 
First, rewinding head to replay your work on top of it...
 
Applying: laji
 
[root@localhost wanyan]# cat rebase1
 
first
 
two
 
[root@localhost wanyan]# cat rebase2
 
 
 
[root@localhost wanyan]# git branch master
 
fatal: A branch named 'master' already exists.
 
[root@localhost wanyan]# git checkout  master
 
Switched to branch 'master'
 
[root@localhost wanyan]# cat rebase2
 
 
 
[root@localhost wanyan]# cat rebase2
 
 
 
[root@localhost wanyan]# cat rebase1
 
first
 
这个是单独的实例仅仅为了理解原理,无实践意义。
(责任编辑:IT)
------分隔线----------------------------