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


目录
相关文章
|
8天前
|
缓存 开发工具 git
Git创建分支以及合并分支
在Git中,创建分支使用`git branch [branch_name]`,切换分支使用`git checkout [branch_name]`。修改文件后,通过`git add [file]`添加到暂存区,然后`git commit`提交到本地仓库。如果是新建分支的第一次推送,使用`git push origin [branch_name]`推送到远程仓库,之后可以简化为`git push`。合并分支时,使用`git merge [branch_name]`将指定分支的更改合并到当前分支。
13 2
Git创建分支以及合并分支
|
4月前
|
项目管理 开发工具 git
Git项目管理——分支(三)
Git项目管理——分支(三)
55 2
|
5天前
|
存储 Linux 开发工具
Git基础命令,分支,标签的使用【快速入门Git】
本文详细介绍了Git版本控制系统的基础概念和常用命令,包括工作区、暂存区和版本库的区别,文件状态的变化,以及如何进行文件的添加、提交、查看状态、重命名、删除、查看提交历史、远程仓库操作和分支管理,还涉及了Git标签的创建和删除,旨在帮助读者快速入门Git。
Git基础命令,分支,标签的使用【快速入门Git】
|
19天前
|
测试技术 开发工具 git
掌握 Git 分支策略:提升你的版本控制技能
在现代软件开发中,版本控制至关重要,Git 作为最流行的分布式版本控制系统,其分支管理策略对于高效协作和代码维护尤为重要。本文介绍了几种常用的 Git 分支策略,包括主线开发模型、功能分支模型、Gitflow 工作流和 Forking 工作流,并探讨了如何根据项目需求选择合适的分支模型。通过保持 `master` 分支稳定、及时合并清理分支、使用命名规范、利用 Pull Request 进行代码审查及自动化测试等最佳实践,可以显著提升团队协作效率和软件质量。掌握这些策略将帮助开发者更好地管理代码库,加快开发流程。
|
5月前
|
JSON 开发工具 git
git rebase 合并当前分支的多个commit记录
git rebase 合并当前分支的多个commit记录
|
2月前
|
开发工具 git 开发者
|
2月前
|
项目管理 开发工具 git
|
2月前
|
存储 小程序 安全
【技巧】git stash用的好,切换分支随便搞
本文详细介绍了 Git 中的 `git stash` 命令,帮助你在切换分支时临时保存未提交的更改。通过实际操作示例,展示了如何使用 `git stash` 的各种命令,如 `save`、`list`、`apply` 等。无论你是初学者还是有一定经验的开发者,都能从中受益。
33 0
【技巧】git stash用的好,切换分支随便搞
|
2月前
|
Shell 开发工具 git
|
2月前
|
JavaScript 测试技术 开发工具
Git 分支设计规范
Git 分支设计规范
88 11