揭开Git分支的面纱

简介: 每一次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

揭开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:


Staging the files computes a checksum for each one


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


adds that checksum to the staging area


when you create a commit


stores blobs as a tree object

create a commit object

``commit object 存储着对tree object`的引用以及此次提交的其他信息



20200423191648613.png


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指针指向该分支



20200423191709234.png


4 Git分支的基本操作

创建分支


git branch 分支名


删除分支


git branch -d 分支名


切换分支


git checkout 分支名


创建并切换分支


git checkout -b 分支名


查看各个分支log


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


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


目录
相关文章
|
1月前
|
开发工具 git 开发者
|
1月前
|
开发工具 git
|
2月前
|
前端开发 算法 开发工具
Git分支批量清理利器:自定义命令行插件实战
Git分支批量清理利器:自定义命令行插件实战
44 0
|
开发工具 git
Git版本控制——分支
几乎所有的版本控制系统都以某种形式支持分支。使用分支意味着可以把工作从开发主线上分离开来进行重大的Bug修改、开发新的功能,以免影响开发主线。
32 0
|
2月前
|
开发工具 git
Git从远程仓库拉取指定的分支
Git从远程仓库拉取指定的分支
98 0
|
3月前
|
存储 开发工具 git
Pycharm git-创建本地仓库\创建分支\合并分支\回溯版本\加入git后文件颜色代表的含义
Pycharm git-创建本地仓库\创建分支\合并分支\回溯版本\加入git后文件颜色代表的含义
68 0
|
1月前
|
开发工具 git 开发者
|
1月前
|
开发工具 git
|
4月前
|
数据可视化 Go 开发工具
cggit 简化 Git 提交、合并、分支偏移小神器,提升开发、修BUG效率!
cggit 简化 Git 提交、合并、分支偏移小神器,提升开发、修BUG效率!
40 0
|
1月前
|
存储 开发工具 git
Git 术语解析:深入理解上游分支
【2月更文挑战第26天】
87 0
Git 术语解析:深入理解上游分支

相关实验场景

更多