码迷,mamicode.com
首页 > 其他好文 > 详细

worktools-git 工具的使用总结(2)

时间:2015-02-26 20:09:47      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

1.创建分支

//创建分支,是在master 分支的基础上创建


zhangshuli@zhangshuli-MS-7817:~/myGit$ git st # On branch master nothing to commit (working directory clean) zhangshuli@zhangshuli-MS-7817:~/myGit$ ls aaa.txt zhangshuli@zhangshuli-MS-7817:~/myGit$ git branch second master zhangshuli@zhangshuli-MS-7817:~/myGit$ git br -av * master f73968d my second commit second f73968d my second commit 

星号表示当前所处的分支,一般master是主分支

2.删除分支

zhangshuli@zhangshuli-MS-7817:~/myGit$ git br -av
* master f73968d my second commit
  second f73968d my second commit
zhangshuli@zhangshuli-MS-7817:~/myGit$ git branch -d master 
error: Cannot delete the branch master which you are currently on.
zhangshuli@zhangshuli-MS-7817:~/myGit$ git branch -d second 
Deleted branch second (was f73968d).
zhangshuli@zhangshuli-MS-7817:~/myGit$ git br -av
* master f73968d my second commit
zhangshuli@zhangshuli-MS-7817:~/myGit$

我们不能删除当前所处的分支

zhangshuli@zhangshuli-MS-7817:~/myGit$ git branch second master 
zhangshuli@zhangshuli-MS-7817:~/myGit$ git br -av
* master f73968d my second commit
  second f73968d my second commit
zhangshuli@zhangshuli-MS-7817:~/myGit$ git checkout second 
Switched to branch second
zhangshuli@zhangshuli-MS-7817:~/myGit$ git br -av
  master f73968d my second commit
* second f73968d my second commit
zhangshuli@zhangshuli-MS-7817:~/myGit$ git branch -d master 
Deleted branch master (was f73968d).
zhangshuli@zhangshuli-MS-7817:~/myGit$ 

事实证明,主分支也是可以删除的,这个似乎不存在所谓的父类节点关系,倒是更像 拷贝

3.探索两个分支间的关系

zhangshuli@zhangshuli-MS-7817:~/myGit$ git br -av
* second 2e32a61 master add
zhangshuli@zhangshuli-MS-7817:~/myGit$ git branch son second 
zhangshuli@zhangshuli-MS-7817:~/myGit$ git br -av
* second 2e32a61 master add
  son    2e32a61 master add
zhangshuli@zhangshuli-MS-7817:~/myGit$ git log
commit 2e32a615216de70720d314b8fe53c1bddccfd6a3
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Thu Feb 26 16:55:33 2015 +0000

    master add

commit f73968df521e48d23289c5563f7ac7fbc5937b57
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Fri Feb 13 13:24:15 2015 +0000

    my second commit

commit 4c7cede87be37783ca4528fbdcd79bc08e3870fe
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Fri Feb 13 10:54:58 2015 +0000

    my frist commit
zhangshuli@zhangshuli-MS-7817:~/myGit$ git checkout son 
Switched to branch son
zhangshuli@zhangshuli-MS-7817:~/myGit$ git br -av
  second 2e32a61 master add
* son    2e32a61 master add
zhangshuli@zhangshuli-MS-7817:~/myGit$ git log
commit 2e32a615216de70720d314b8fe53c1bddccfd6a3
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Thu Feb 26 16:55:33 2015 +0000

    master add

commit f73968df521e48d23289c5563f7ac7fbc5937b57
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Fri Feb 13 13:24:15 2015 +0000

    my second commit

commit 4c7cede87be37783ca4528fbdcd79bc08e3870fe
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Fri Feb 13 10:54:58 2015 +0000

    my frist commit
zhangshuli@zhangshuli-MS-7817:~/myGit$

1)创建分支以后,两个分支的内容完全相同

 

zhangshuli@zhangshuli-MS-7817:~/myGit$ vim ccc.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ git st 
# On branch son
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#    ccc.txt
nothing added to commit but untracked files present (use "git add" to track)
zhangshuli@zhangshuli-MS-7817:~/myGit$ git commit
# On branch son
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#    ccc.txt
nothing added to commit but untracked files present (use "git add" to track)
zhangshuli@zhangshuli-MS-7817:~/myGit$ git add .
zhangshuli@zhangshuli-MS-7817:~/myGit$ git st 
# On branch son
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#    new file:   ccc.txt
#
zhangshuli@zhangshuli-MS-7817:~/myGit$ git checkout second 
A    ccc.txt
Switched to branch second
zhangshuli@zhangshuli-MS-7817:~/myGit$ git log
commit 2e32a615216de70720d314b8fe53c1bddccfd6a3
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Thu Feb 26 16:55:33 2015 +0000

    master add

commit f73968df521e48d23289c5563f7ac7fbc5937b57
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Fri Feb 13 13:24:15 2015 +0000

    my second commit

commit 4c7cede87be37783ca4528fbdcd79bc08e3870fe
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Fri Feb 13 10:54:58 2015 +0000

    my frist commit
zhangshuli@zhangshuli-MS-7817:~/myGit$ ls
aaa.txt  bbb.txt  ccc.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$

2)当我在子分支上添加了一个修改的时候,父分支会跟着做相应的修改

zhangshuli@zhangshuli-MS-7817:~/myGit$ git br -av
* parent 5ad0d1e parent test
  son    2974d86 son test
zhangshuli@zhangshuli-MS-7817:~/myGit$ ls
aaa.txt  bbb.txt  ddd.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ git log -1
commit 5ad0d1ece9b7fd69a9e4deb990c8a4d05d2cbee1
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Thu Feb 26 17:32:39 2015 +0000

    parent test
zhangshuli@zhangshuli-MS-7817:~/myGit$ git checkout son 
Switched to branch son
zhangshuli@zhangshuli-MS-7817:~/myGit$ ls
aaa.txt  bbb.txt  ccc.txt  ddd.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ git log -1
commit 2974d86cea7341e5921368ceb708c61f7c77e6c5
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Thu Feb 26 17:26:11 2015 +0000


    son test
zhangshuli@zhangshuli-MS-7817:~/myGit$ vim add.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ vim commit.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ git add add.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ git add commit.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ git commit commit.txt
[son 17619d8] son commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 commit.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ ls
aaa.txt  add.txt  bbb.txt  ccc.txt  commit.txt  ddd.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ git st 
# On branch son
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#    new file:   add.txt
#
zhangshuli@zhangshuli-MS-7817:~/myGit$ git log -1
commit 17619d87e77a80ef744be6b542cd87ef2f62b71e
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Thu Feb 26 17:36:32 2015 +0000

    son commit
zhangshuli@zhangshuli-MS-7817:~/myGit$ git checkout parent 
A    add.txt
Switched to branch parent
zhangshuli@zhangshuli-MS-7817:~/myGit$ ls
aaa.txt  add.txt  bbb.txt  ddd.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ ls
aaa.txt  add.txt  bbb.txt  ddd.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ git st 
# On branch parent
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#    new file:   add.txt
#
zhangshuli@zhangshuli-MS-7817:~/myGit$ git log -1
commit 5ad0d1ece9b7fd69a9e4deb990c8a4d05d2cbee1
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Thu Feb 26 17:32:39 2015 +0000

    parent test
zhangshuli@zhangshuli-MS-7817:~/myGit$

3)终于可以对分支盖棺定论了,原来是这样的,两个分支是同步的,直到其中的一个进行了commit,否则,当我们切换两个有父子关系的分支的时候,分支会自动merge,如果父分支创建了子分支已经存在的文件,你会发现会有merge冲突。如下

zhangshuli@zhangshuli-MS-7817:~/myGit$ git st 
# On branch parent
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#    new file:   add.txt
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#    modified:   aaa.txt
#
zhangshuli@zhangshuli-MS-7817:~/myGit$ git checkout son 
M    aaa.txt
A    add.txt
Switched to branch son
zhangshuli@zhangshuli-MS-7817:~/myGit$ git st .
# On branch son
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#    new file:   add.txt
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#    modified:   aaa.txt
#
zhangshuli@zhangshuli-MS-7817:~/myGit$ vim aaa.txt 
zhangshuli@zhangshuli-MS-7817:~/myGit$ vim commit.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ git checkout parent 
M    aaa.txt
A    add.txt
Switched to branch parent
zhangshuli@zhangshuli-MS-7817:~/myGit$ vim commit.txt
zhangshuli@zhangshuli-MS-7817:~/myGit$ git checkout son 
error: Untracked working tree file commit.txt would be overwritten by merge.
zhangshuli@zhangshuli-MS-7817:~/myGit$

如果我们把修改提交了,那么你就会发现两个分支是完全不关联的

worktools-git 工具的使用总结(2)

标签:

原文地址:http://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_zj_150226181.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!