指令視覺化
用圖把常用指令放回四個區域裡。對照 Git 常用指令 一起看會比較快。
資料怎麼流動
sequenceDiagram
participant A as Working Directory
participant B as Staging Area
participant C as Local Repo
participant D as Remote Repo
A ->> B: git add
B ->> C: git commit
C ->> D: git push
D -->> C: git fetch
C -->> A: git merge
D -->> A: git pull
D -->> A: git clone
git pull可以想成fetch再加上把遠端變更合併進目前分支。git clone一次把遠端歷史變成新的本機專案。
區域與指令對照
graph TD
A[Workspace] -- git add --> B[Staging]
B -- git commit --> C[Local Repository]
C -- git push --> D[Remote Repository]
D -- git pull --> C
C -- git reset --> B
B -- "git restore --staged" --> A
A -- git restore --> A
C -- git fetch --> C
C -- git merge/rebase --> C
還原類指令的副作用差很多,選之前先看 復原修改。