揭开Git分支的面纱

Branches in a Nutshell

Branching means you diverge from the main line of development and continue to do work without messing with that main line

Git can change the way that you develop

  • 每一次stage、commit背后,Git都做了些什么?

A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is master. As you start making commits, you’re given a master branch that points to the last commit you made. Every time you commit, the master branch pointer moves forward automatically.

How does Git know what branch you’re currently on? It keeps a special pointer called HEAD

1.分支是什么?

Branching means you diverge from the main line of development and continue to do work without messing with that main line

2 揭秘每一次stage、commit背后故事

when you stage

  1. Staging the files computes a checksum for each one

  2. stores that version of the file in the Git repository (Git refers to them as blobs),

  3. adds that checksum to the staging area

when you create a commit

  1. stores blobs as a tree object
  2. create a commit object
  3. ``commit object 存储着对tree object`的引用以及此次提交的其他信息

在这里插入图片描述

3 Git中的branch

A branch in Git is simply a lightweight movable pointer to one of these commits.

如下面的testing分支

How does Git know what branch you’re currently on? It keeps a special pointer called HEAD

HEAD指针指向当前所在分支,切换分支,就是将HEAD指针指向该分支

在这里插入图片描述

4 Git分支的基本操作

  1. 创建分支

    git branch 分支名

  2. 删除分支

    git branch -d 分支名

  3. 切换分支

    git checkout 分支名

  4. 创建并切换分支

    git checkout -b 分支名

  5. 查看各个分支log

    git log --oneline --decorate --graph --all

    git log默认是查看当期分支下的log

更多讨论:https://github.com/pluscai/use-git/issues/22

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值