It will be a little hard to describe Git branching well , so I may vastly reference contents from 《Pro Git》

Before the introduction of Git Branching, let’s see what git actually dose when we are making commit by running command git commit at first.

Figure 1.1

when you create the commit by running git commit, Git checksums each
subdirectory and stores them as a tree object in the Git repository.
Then Git creates a commit object that has the metadata and a pointer
to the root project tree so it can re-create that snapsht when needed. --《Pro Git》

You can see now we have five objects in our git repository, they are three blobs, one tree and one commit.


Figure 1.2

The figure1.2 shows that If you update somethings and make commit again, the next commit will stores a pointer to the commit that came instantaneously before it.
A branch in Git is simply a lightweigh movable pointer to one of these commits. The default branch name in Git is master, Every time you commit, the master branch pointer moves forward automatically.


Figure 1.3 A branch and its commit history


Creating a New Branch

It is very easy to create a new branch in git, you just run need to run ‘git branch <name>’ and then run ‘git branch’ to show the branchs you have in Git repository.
for example:

(base) -a01:testGit $ git branch
* master
(base) -a01:testGit $ git branch testing
(base) -a01:testGit $ git branch
* mastertesting


Figure 1.4

Now we have a new branch its name is ‘newbranch’. Git keeps a special pointer called HEAD to indicate which branch you are currently on, from figure1.4 we can know now we are on master branch.

Now let’s do some changes on branch master and commit it, then checkout testing branch also do some works.

(base) -a01:testGit $ vim a.txt
(base) -a01:testGit $ git add a.txt
(base) -a01:testGit $ git commit -m 'branch master'
[master 5a91b37] branch master1 file changed, 1 insertion(+)create mode 100644 a.txt

At first we create file a.txt on branch master.

(

base) -a01:testGit $ git checkout testing
Switched to branch 'testing'
(base) -a01:testGit $ ls
(base) -a01:testGit $ vim test.txt
(base) -a01:testGit $ git add test.txt
(base) -a01:testGit $ git commit -m 'branch testing'
[testing 077303d] branch testing1 file changed, 1 insertion(+)create mode 100644 test.txt

Then checkout on branch testing and create a file test.txt.

(base) -a01:testGit $ git checkout master
Switched to branch 'master'
(base) -a01:testGit $ ls
a.txt

And back to branch master, you can see the file test.txt we add on branch testing doesn’t exist here.

Here is a picture can exactly explain what tis he current situation:

Figure 1.5
We created and switched to a branch, did some work on it, and then switched back to your main branch and did other work. Both of those changes are isolated in separate branches.

That is the the most basic but most useful feature of branching.

Git Branching相关推荐

  1. git-flow的分支管理 (Git branching model)

    master分支(下版开发, 开始测试后锁分支) 热修复分支(基于tag拉分支) 发布分支(暂不用,除非有多余的测试资源,并行测试) 开发分支(暂不用) 功能分支(长期的功能开发) master分支+ ...

  2. 分享一个学习git的图形化学习网站-Learn Git Branching参考答案整理

    分享一个学习git的图形化学习网站:Learn Git Branching 初次学习点这里 这个链接可以跳过前面的帮助信息直接进入:Learn Git Branching 老手点这里 LearnGit ...

  3. learn git branching学习整理3

    介绍 learn git branching是一个非常好的git学习网站,它与传统的文字讲解相比较起来有一个非常大的亮点----图形化的git提交树可以实时的反馈并告诉你当前所做的git操作在对于代码 ...

  4. Learn Git Branching 学习笔记(移动提交记录篇)

    目录 一.移动提交记录篇 1.Git Cherry-pick 2.交互式rebase Git用法高级篇在上一篇文章中Learn Git Branching 学习笔记(高级篇)_流年--by gone的 ...

  5. Learn Git Branching 记录

    Learning Git Branching 可以说是目前为止最好的教程了,地址 点击右下角问号显示常用命令 1.提交 git commit 提交内容,并把这些修改保存成了一个提交记录 C3,C3 的 ...

  6. Learn Git Branching 学习笔记(高级话题篇)

    目录 一.高级话题篇 1.多分支rebase 2.选择父提交记录 3.纠缠不清的分支 Git的一些技术.技巧与贴士集合在上一篇文章中 Learn Git Branching 学习笔记(Git 技术.技 ...

  7. git 指令学习和熟悉——learn git branching练习笔记

    前言: 在工作中我们用到git系列工具机会很多,也常常需要熟悉git 相关指令,那怎样才能高效学习git指令呢?我们可以通过小游戏learn git branching和菜鸟教程完成学习. 小游戏链接 ...

  8. Learn Git Branching:在游戏中学会Git

    Learn Git Branching:在游戏中学会Git Learn Git Branching是一个学习Git操作的教程,作者为不同的命令设计了相应的关卡,它并不枯燥乏味,相反,我们每通过一个关卡 ...

  9. A successful Git branching model

    原文:http://nvie.com/posts/a-successful-git-branching-model/ In this post I present the development mo ...

  10. 【版本控制管理】 深入 001 A successful Git branching model GIT 项目分支策略和释放管理

    本文,转于老外的一个实际git的管理项目和想法.这篇文章作者把自己工作中实际使用git的版本控制构建做了总结.对的,就是git 的版本管理的构架.文章列举了一个复杂的项目开发生命维护的框架,构建了一个 ...

最新文章

  1. “#ifdef __cplusplus extern C { #endif”的定义(zz)
  2. 2012年度IT博客大赛50强报道:张世锋
  3. 【开发工具】Jupyter Notebook 的快捷键
  4. Microsoft Azure Tutorial: Build your first movie inventory web app with just a few lines of code
  5. java中Locks的使用
  6. 作为程序员,北漂的我有很多话想说。
  7. QT链接DLL库问题记录
  8. JAVA websocket中 spring无法注入依赖问题解决
  9. php 热点图,JavaScript_javascript如何写热点图,在gis中,你如果用js来写热点 - phpStudy...
  10. linux es数据库 head,Elasticsearch 5.3.x 使用 Head 插件
  11. hdu 1281 棋盘游戏 (二分匹配)
  12. 网络多人游戏架构pdf_21秒看尽ImageNet屠榜模型,60+模型架构同台献艺
  13. 设计一函数,求整数区间[a,b]和[c,d]的交集
  14. windows 验证tftp服务器,细说Windows tftp服务器配置
  15. html滚动轮播图片代码,html 无缝轮播图完整代码
  16. C语言函数中的px是什么,C语言学习知识程序设计试卷及其规范标准答案
  17. 隔空投送教程|如何将文件从iPhone或iPad空投到Mac计算机?
  18. 樱花飘落的季节——樱花(Python代码实现)
  19. Python结合MySQL数据库编写简单信息管理系统
  20. kingcms php 下载,KingCMS PHP 2009版盛大发布

热门文章

  1. 2020电赛F题总结回顾(openmv实现视觉)
  2. 【C语言】蓝桥杯/ACM竞赛入门 A+B for Input-Output Practice
  3. 网站打不开如何解决?教你4个方法搞定它!
  4. 机器人改变生活利弊英语作文_机器人的利弊作文
  5. java basic认证_HTTP Basic auth认证
  6. 知物由学 | SO加固如何提升Android应用的安全性?
  7. python代码变成so
  8. TokenGazer《一问到底》| 第55期:研究员 VS Dimension
  9. 计算机怎么算折扣价格,5折怎么算-商场打折背后的猫腻:满100减50和打5折哪个更划算?...
  10. 打开chm手册显示已取消到该网页的导航