1.创建分支 git branch son parent

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

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

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

2.删除分支 git branch -d son(如果你想要删除的分支不能删除,这时候你可以使用-D强制删除)

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

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

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

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

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

zhangshuli@zhangshuli-MS-:~/myGit$ git br -av
* second 2e32a61 master add
zhangshuli@zhangshuli-MS-:~/myGit$ git branch son second
zhangshuli@zhangshuli-MS-:~/myGit$ git br -av
* second 2e32a61 master add
son 2e32a61 master add
zhangshuli@zhangshuli-MS-:~/myGit$ git log
commit 2e32a615216de70720d314b8fe53c1bddccfd6a3
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Thu Feb :: + master add commit f73968df521e48d23289c5563f7ac7fbc5937b57
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Fri Feb :: + my second commit commit 4c7cede87be37783ca4528fbdcd79bc08e3870fe
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Fri Feb :: + my frist commit
zhangshuli@zhangshuli-MS-:~/myGit$ git checkout son
Switched to branch 'son'
zhangshuli@zhangshuli-MS-:~/myGit$ git br -av
second 2e32a61 master add
* son 2e32a61 master add
zhangshuli@zhangshuli-MS-:~/myGit$ git log
commit 2e32a615216de70720d314b8fe53c1bddccfd6a3
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Thu Feb :: + master add commit f73968df521e48d23289c5563f7ac7fbc5937b57
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Fri Feb :: + my second commit commit 4c7cede87be37783ca4528fbdcd79bc08e3870fe
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Fri Feb :: + my frist commit
zhangshuli@zhangshuli-MS-:~/myGit$

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

zhangshuli@zhangshuli-MS-:~/myGit$ vim ccc.txt
zhangshuli@zhangshuli-MS-:~/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-:~/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-:~/myGit$ git add .
zhangshuli@zhangshuli-MS-:~/myGit$ git st
# On branch son
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: ccc.txt
#
zhangshuli@zhangshuli-MS-:~/myGit$ git checkout second
A ccc.txt
Switched to branch 'second'
zhangshuli@zhangshuli-MS-:~/myGit$ git log
commit 2e32a615216de70720d314b8fe53c1bddccfd6a3
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Thu Feb :: + master add commit f73968df521e48d23289c5563f7ac7fbc5937b57
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Fri Feb :: + my second commit commit 4c7cede87be37783ca4528fbdcd79bc08e3870fe
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Fri Feb :: + my frist commit
zhangshuli@zhangshuli-MS-:~/myGit$ ls
aaa.txt bbb.txt ccc.txt
zhangshuli@zhangshuli-MS-:~/myGit$

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

zhangshuli@zhangshuli-MS-:~/myGit$ git br -av
* parent 5ad0d1e parent test
son 2974d86 son test
zhangshuli@zhangshuli-MS-:~/myGit$ ls
aaa.txt bbb.txt ddd.txt
zhangshuli@zhangshuli-MS-:~/myGit$ git log -
commit 5ad0d1ece9b7fd69a9e4deb990c8a4d05d2cbee1
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Thu Feb :: + parent test
zhangshuli@zhangshuli-MS-:~/myGit$ git checkout son
Switched to branch 'son'
zhangshuli@zhangshuli-MS-:~/myGit$ ls
aaa.txt bbb.txt ccc.txt ddd.txt
zhangshuli@zhangshuli-MS-:~/myGit$ git log -
commit 2974d86cea7341e5921368ceb708c61f7c77e6c5
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Thu Feb :: + son test
zhangshuli@zhangshuli-MS-:~/myGit$ vim add.txt
zhangshuli@zhangshuli-MS-:~/myGit$ vim commit.txt
zhangshuli@zhangshuli-MS-:~/myGit$ git add add.txt
zhangshuli@zhangshuli-MS-:~/myGit$ git add commit.txt
zhangshuli@zhangshuli-MS-:~/myGit$ git commit commit.txt
[son 17619d8] son commit
files changed, insertions(+), deletions(-)
create mode commit.txt
zhangshuli@zhangshuli-MS-:~/myGit$ ls
aaa.txt add.txt bbb.txt ccc.txt commit.txt ddd.txt
zhangshuli@zhangshuli-MS-:~/myGit$ git st
# On branch son
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: add.txt
#
zhangshuli@zhangshuli-MS-:~/myGit$ git log -
commit 17619d87e77a80ef744be6b542cd87ef2f62b71e
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Thu Feb :: + son commit
zhangshuli@zhangshuli-MS-:~/myGit$ git checkout parent
A add.txt
Switched to branch 'parent'
zhangshuli@zhangshuli-MS-:~/myGit$ ls
aaa.txt add.txt bbb.txt ddd.txt
zhangshuli@zhangshuli-MS-:~/myGit$ ls
aaa.txt add.txt bbb.txt ddd.txt
zhangshuli@zhangshuli-MS-:~/myGit$ git st
# On branch parent
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: add.txt
#
zhangshuli@zhangshuli-MS-:~/myGit$ git log -
commit 5ad0d1ece9b7fd69a9e4deb990c8a4d05d2cbee1
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Thu Feb :: + parent test
zhangshuli@zhangshuli-MS-:~/myGit$

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

zhangshuli@zhangshuli-MS-:~/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-:~/myGit$ git checkout son
M aaa.txt
A add.txt
Switched to branch 'son'
zhangshuli@zhangshuli-MS-:~/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-:~/myGit$ vim aaa.txt
zhangshuli@zhangshuli-MS-:~/myGit$ vim commit.txt
zhangshuli@zhangshuli-MS-:~/myGit$ git checkout parent
M aaa.txt
A add.txt
Switched to branch 'parent'
zhangshuli@zhangshuli-MS-:~/myGit$ vim commit.txt
zhangshuli@zhangshuli-MS-:~/myGit$ git checkout son
error: Untracked working tree file 'commit.txt' would be overwritten by merge.
zhangshuli@zhangshuli-MS-:~/myGit$

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

4.分支变基 git rebase

zhangshuli@zhangshuli-MS-:~/myGit$ git checkout son
Switched to branch 'son'
zhangshuli@zhangshuli-MS-:~/myGit$ vim aaa.txt
zhangshuli@zhangshuli-MS-:~/myGit$ git st
# On branch son
# 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
#
no changes added to commit (use "git add" and/or "git commit -a")
zhangshuli@zhangshuli-MS-:~/myGit$ git add .
zhangshuli@zhangshuli-MS-:~/myGit$ git commit -m "son rebase"
[son e2e09c4] son rebase
files changed, insertions(+), deletions(-)
zhangshuli@zhangshuli-MS-:~/myGit$ git log -
commit e2e09c4898f9246b1d0fab2dc6845506f5960742
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date: Fri Feb :: + son rebase
zhangshuli@zhangshuli-MS-:~/myGit$ git rebase parent
Current branch son is up to date.
zhangshuli@zhangshuli-MS-:~/myGit$ git br -av
parent 5ad0d1e parent test
* son e2e09c4 son rebase
zhangshuli@zhangshuli-MS-:~/myGit$ git checkout parent
Switched to branch 'parent'
zhangshuli@zhangshuli-MS-:~/myGit$ git rebase son
First, rewinding head to replay your work on top of it...
Fast-forwarded parent to son.
zhangshuli@zhangshuli-MS-:~/myGit$ ls
aaa.txt bbb.txt ccc.txt ddd.txt
zhangshuli@zhangshuli-MS-:~/myGit$ vim aaa.txt
zhangshuli@zhangshuli-MS-:~/myGit$

具体关于git reset 跟 git rebase的区别联系,参考飞林沙的博文git rebase(转)

之前有一点一直弄不明白,就是自己想把son rebase到parent上的时候,这时候我执行如下命令

git checkout son

git rebase parent

是不行的,后来才发现,当你希望把son rebase parent上的时候,必须先切换到parent,然后在git rebase son

worktools-git 工具的使用总结(2)的更多相关文章

  1. 【转】第 02 天:在 Windows 平台必裝的三套 Git 工具

    原文网址:https://github.com/doggy8088/Learn-Git-in-30-days/blob/master/docs/02%20%E5%9C%A8%20Windows%20% ...

  2. windows中使用Git工具连接GitHub(配置篇)

    Git在源码管理领域目前占很大的比重了,而且开源的项目很多都转到GitHub上面了.例如:jQuery, reddit, Sparkle, curl, Ruby on Rails, node.js,  ...

  3. Git详解之六 Git工具(转)

    Git 工具 现在,你已经学习了管理或者维护 Git 仓库,实现代码控制所需的大多数日常命令和工作流程.你已经完成了跟踪和提交文件的基本任务,并且发挥了暂存区和轻量级的特性分支及合并的威力. 接下来你 ...

  4. Git详解之六:Git工具

    Git 工具 现在,你已经学习了管理或者维护 Git 仓库,实现代码控制所需的大多数日常命令和工作流程.你已经完成了跟踪和提交文件的基本任务,并且发挥了暂存区和轻量级的特性分支及合并的威力.(伯乐在线 ...

  5. 使用git工具将项目上传到github

    注册github账号 https://github.com/ 安装git工具: https://git-for-windows.github.io/ 上面的准备工作完成后,现在开始操作. 一.进入gi ...

  6. Git工具的使用教程

    Git 是一种版本控制工具,也叫作版本管理软件(分布式管理软件).这里介绍Git的基本使用步骤,关于 Git 更详细的介绍,读者可以参考其官方网站提供的文档. 1  安装Git 在Ubuntu系统中安 ...

  7. 使用git工具快速push项目到github(精简)

    Dear Weber ,相信有很多刚开始接触前端的程序猿,在刚接触到git工具传项目到github上时会遇到一些问题,那么下面的话呢,我就整理一下一个大致的思路提供给大家参考: 工具:git (自行下 ...

  8. 代码管理工具:使用github和git工具管理自己的代码

    一.git工具和账户创建 1.1 安装 Git 是 Linus Torvalds 最近实现的源代码管理软件."Git 是一个快速.可扩展的分布式版本控制系统,它具有极为丰富的命令集,对内部系 ...

  9. 使用git工具上传自己的程序到github上

    一:前期准备 可以运行的项目 github账号 git工具 二:开始操作 1.创建个人github仓库 写自己项目的名字,描述,权限,README 2.新建结束后会进入如下界面 3.复制仓库地址 4. ...

  10. Git工具使用

    GIT(分布式版本控制系统) Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.Git的读音为/gɪt/. Git是一个开源的分布式版本控制系统,可以有效.高速的处理从 ...

随机推荐

  1. 洛谷——P1966 火柴排队

    https://www.luogu.org/problem/show?pid=1966 题目描述 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度. 现在将每盒中的火柴各自排成一列, 同一列 ...

  2. ubuntu中开启、关闭防火墙

    1.关闭ubuntu的防火墙        ufw disable 开启防火墙 ufw enable 2.卸载了iptables        apt-get remove iptables 3.关闭 ...

  3. Visual Code的调试

    Run 'Debug: Download .NET Core Debugger' in the Command Palette or open a .NET project directory to ...

  4. .Net中字典的使用

    /// <summary> /// 获取用户市信息 /// </summary> /// <param name="CustomerId">&l ...

  5. netflix feign概述

    1.什么是feign?feign的作用是什么? Feign is a java to http client binder inspired by Retrofit, JAXRS-2.0, and W ...

  6. java.util.logging.FileHandler

    java.util.logging.FileHandler java自带的日志功能,FileHandler可以写日志到文件系统,并且自己维护日志的增删,比c++不知道强多少 FileHandler(f ...

  7. 记录一下sql两个表关联的查询使用方法

    SELECT * FROM t_yymp_user_info where user_id = (select b.user_id from t_yymp_auth_role as a,t_yymp_a ...

  8. cf 865 B. Ordering Pizza

    B. Ordering Pizza It's another Start[c]up finals, and that means there is pizza to order for the ons ...

  9. Mark Compact GC (Part one: Lisp2)

    目录 什么是GC 标记-压缩算法 Lisp2 算法的对象 概要 步骤 步骤一:设定forwarding指针 步骤二:更新指针 步骤三:移动对象 优缺点 什么是GC 标记-压缩算法 需要对标记清除和GC ...

  10. jq 克隆 移除table

    function addRow2(node){ var obj = $("tr[name='info']:last"); var objClone = $(obj).clone() ...