擁抱 Git CLI
ToC
為什麼要用 CLI
Pros:
- 搭配 vi, vscode, sublime 等工具, 編輯 commit message(別人都已打完 message,而你還在等 IDE 開編輯訊息的彈窗?
- Learn once, use everywhere!
- 不需要滑鼠(你也有滑鼠突然沒電的困擾嗎?
- 提升英打速度(?
- 完整高階指令支援 e.g.,
git log --grep 'some message'
Cons:
概念
日常操作,僅需熟悉以下七個指令就已足夠
指令 |
說明 |
git branch my-branch |
開始開發,開一個新分支 |
git checkout my-branch |
切換至該新分支 |
git add -p |
增加修改的檔案至暫存區 |
git commit -m"first commit" |
將暫存區的檔案提交至本地儲存庫 |
git fetch origin develop |
取得遠端分支的資訊 |
git rebase origin/develop |
遠端分支可能有更新,要先 rebase 分支 |
git push origin my-branch |
推當前分支至遠端 |
檔案狀態
每個檔案都有三個對應的狀態:
checkout 用來切換紀錄
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
延伸閱讀 git object of the Git Book
branch / tag 都只是 SHA1 的別名
只要有 git 就一定會處於 HEAD ,任何變更都會影響到當前的 HEAD
HEAD -> 9afc5562
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
HEAD -> feature/sticky-table-ernest -> 9afc5562
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
操作都是在 HEAD 指向的紀錄上執行
HEAD 沒有指向任何分支,此時 Commit 一筆紀錄,僅 HEAD 自己會指到新的 SHA1,而其他分支不會影響
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
HEAD 指向某一分支,此時 Commit 一筆紀錄,HEAD、分支都會跟著指到新的 SHA1
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
延伸閱讀 HEAD~ HEAD^ 有何不同
接力
總結
遇到困難怎麼辦?
直接找官方文件是最周全的方式:
the Git Book
此外也可以利用以下指令查詢:
git help
git help tutorial
git help everyday
搭配視覺化的練習網站
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
參考來源