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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章