Git 筆記 (7-1) git branch

git 專案分支範例


1. 建立一個名為 Git 的資料夾移動到該路徑下,並建立一個 test.py 內容隨意:

$ mkdir Git
$ cd Git
$ touch test.py

2. 建立 repository:

$ git init
$ git add .
$ git commit -m "First commit"

3. 建立名為 tmp 的 branch 並切換到 tmp,下面示範兩種方法:

第一種方法,使用 git branch:

$ git branch tmp     # 建立一個名為 tmp 的 branch
$ git cheackout tmp  # 切換到 tmp 

第二種方法,使用 git checkout -b:

$ git checkout -b tmp # 建立一個名為 tmp 的 branch 並切換到 tmp  

!! 注意 windows bash 會顯示現在的分支式 master 還是 tmp


3. 在 tmp 分支下加入 test2.py 並 commit:

$ cp test.py test2.py
$ git add .
$ git commit -m "Add test2.py" 

4. 回到 master 分支並在 master 分支下加入 test3.py:

$ git checkout master
$ cp test.py test3.py
$ git add .
$ git commit -m "Add test3.py" 

5. 使用 gitk --all 可以查看版本樹的狀態:

$ gitk --all

6. 有興趣的人可以試試看:

$ git checkout master
$ ls
$ git checkout tmp
$ ls

留言

熱門文章