Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction of Git

Brian
March 29, 2021

Introduction of Git

Brian

March 29, 2021
Tweet

More Decks by Brian

Other Decks in Programming

Transcript

  1. 關於 Git 關於 Git 作者: 作者: Git 的操作可以在⾃⼰ local,不需要網路 Git

    的操作可以在⾃⼰ local,不需要網路 , , 都是透過 Git 進⾏版本控制的原始 都是透過 Git 進⾏版本控制的原始 碼代管服務平台 碼代管服務平台 所有檔案都可以 git,起⼿式 => 所有檔案都可以 git,起⼿式 => git init git init Linus Torvalds Linus Torvalds Github Github Gitlab Gitlab 4 4
  2. Git 的優點 Git 的優點 1. 免費、開源 免費、開源 2. 速度快、檔案體積⼩ 速度快、檔案體積⼩

    Git 並不是記錄版本的差異,⽽是記錄檔案內容的 Git 並不是記錄版本的差異,⽽是記錄檔案內容的 「快照」(snapshot),它可以讓 Git 在非常快 「快照」(snapshot),它可以讓 Git 在非常快 速的切換版本 速的切換版本 3. 分散式系統 分散式系統 5 5
  3. Git 的缺點 Git 的缺點 1. 易學難精 易學難精 2. 非常多指令 (Command

    Line) 非常多指令 (Command Line) ⼆八法則,記住 20% 的指令就很夠⽤ ⼆八法則,記住 20% 的指令就很夠⽤ 有很多圖形化介⾯⼯具輔助,已⼤幅降低使 有很多圖形化介⾯⼯具輔助,已⼤幅降低使 ⽤的⾨檻 ⽤的⾨檻 6 6
  4. 安裝 Git 安裝 Git 下載: 下載: ⼀步到底 ⼀步到底 開啟 Git

    Bash 並輸入以下指令 開啟 Git Bash 並輸入以下指令 https://git-scm.com/download/win https://git-scm.com/download/win $ $ which which git git /mingw64/bin/git /mingw64/bin/git $ git --version $ git --version git version 2.21.0.windows.1 git version 2.21.0.windows.1 7 7
  5. git config git config # 設定 email # 設定 email

    $ git config --global user.email $ git config --global user.email "[email protected]" "[email protected]" # 設定名稱 # 設定名稱 $ git config --global user.name $ git config --global user.name "test" "test" # 檢視⽬前設定 # 檢視⽬前設定 $ git config --list $ git config --list 9 9
  6. git init git init 新增、初始 Repository 新增、初始 Repository # 切換⾄

    /tmp ⽬錄 # 切換⾄ /tmp ⽬錄 $ $ cd cd /tmp /tmp # 建立 git-practice ⽬錄 # 建立 git-practice ⽬錄 $ mkdir git-practice $ mkdir git-practice # 切換⾄ git-practice ⽬錄 # 切換⾄ git-practice ⽬錄 $ $ cd cd git-practice git-practice # 初始化這個⽬錄,讓 Git 對這個⽬錄開始進⾏版控 # 初始化這個⽬錄,讓 Git 對這個⽬錄開始進⾏版控 $ git init $ git init 10 10
  7. 解除 Git 控制 解除 Git 控制 把 把 .git .git

    這個⽬錄移除就可以了!!! 這個⽬錄移除就可以了!!! 11 11
  8. git status git status 查看檔案狀態 查看檔案狀態 顯⽰沒有東⻄可以被提交 (commit) 顯⽰沒有東⻄可以被提交 (commit)

    我們試著新增⼀個檔案看看 我們試著新增⼀個檔案看看 $ git status $ git status Initial commit Initial commit nothing to commit (create/copy files and use nothing to commit (create/copy files and use "git add" "git add" to track) to track) 12 12
  9. git add git add 把檔案放到暫存區 (Staging Area),讓 Git 開始「追 把檔案放到暫存區

    (Staging Area),讓 Git 開始「追 蹤」它 蹤」它 # 加入特定檔案 # 加入特定檔案 $ git add xxx.html $ git add xxx.html # 加入特定副檔名的檔案 # 加入特定副檔名的檔案 $ git add *.html $ git add *.html # 加入全部檔案 # 加入全部檔案 $ git add --all $ git add --all 13 13
  10. git commit git commit 把暫存區的內容提交到倉庫裡存檔 把暫存區的內容提交到倉庫裡存檔 Commit 的 message 非常重要!

    代表這個修改做了什 Commit 的 message 非常重要! 代表這個修改做了什 麼,⼀定要明確表達 麼,⼀定要明確表達 $ git commit -m $ git commit -m "init commit" "init commit" [master (root-commit) dfccf0c] init commit [master (root-commit) dfccf0c] init commit 1 file changed, 1 insertion(+) 1 file changed, 1 insertion(+) create mode 100644 xxx.html create mode 100644 xxx.html 14 14
  11. Push & Pull Push & Pull # 更新遠端上當前分⽀ # 更新遠端上當前分⽀

    $ git push $ git push # 把當前分⽀拉回本機更新 # 把當前分⽀拉回本機更新 $ git pull $ git pull 17 17
  12. Clone Repository Clone Repository # 會使⽤原本的⽬錄名稱 # 會使⽤原本的⽬錄名稱 $ git

    $ git clone clone https://github.com/18chetanpatel/shipit.git https://github.com/18chetanpatel/shipit.git # 後⾯加上名稱,即可存成不同的⽬錄名稱 # 後⾯加上名稱,即可存成不同的⽬錄名稱 $ git $ git clone clone https://github.com/18chetanpatel/shipit.git xxxx https://github.com/18chetanpatel/shipit.git xxxx 18 18
  13. Clone 跟 Pull 這兩個指令的應⽤場景是不同的 Clone 跟 Pull 這兩個指令的應⽤場景是不同的 如果這個專案你是第⼀次看到,想要下載到你的 如果這個專案你是第⼀次看到,想要下載到你的

    電腦裡,請使⽤ Clone 指令 電腦裡,請使⽤ Clone 指令 如果你已經下載回來了,你只是想要更新最新的 如果你已經下載回來了,你只是想要更新最新的 線上版內容,請使⽤ Pull 指令 線上版內容,請使⽤ Pull 指令 19 19
  14. 淺談 Git Flow 淺談 Git Flow 重點是 Flow 是要讓開發團隊所有⼈都遵守同⼀套流程 重點是

    Flow 是要讓開發團隊所有⼈都遵守同⼀套流程 https://gitbook.tw/chapters/gitflow/why-need- https://gitbook.tw/chapters/gitflow/why-need- git-flow.html git-flow.html https://gitbook.tw/chapters/gitflow/using-git- https://gitbook.tw/chapters/gitflow/using-git- flow.html flow.html 20 20