← Foundations Course

SYSTEM FOUNDATIONS · 14

Git / GitHub:把「現在的檔案」變成可追蹤歷史

Git 是版本控制系統;GitHub 是託管 Git repository 與協作/CI 的平台。你要先理解 working tree → staging → commit → remote,而不是只背 push/pull 指令。

Learning outcomes

1. Git 的三個本地層

Working tree
  ↓ git add
Staging area
  ↓ git commit
Local repository history

改了檔案不等於已 commit;commit 也不等於已推到 GitHub。

2. status 是第一個 Evidence

git status

它會告訴你目前 branch、哪些檔案 modified/staged/untracked。遇到 Git 問題先看 status 比盲目 reset 安全。

3. diff / log

git diff
git diff --staged
git log --oneline -5

Diff 告訴你「改了什麼」,log 告訴你「歷史長什麼樣」。

4. Remote / GitHub

local commits
  ↓ git push
origin/main on GitHub

remote commits
  ↓ git fetch / pull
local repository

GitHub 不是 Git 本身,但提供 remote hosting、PR、Actions、permissions 等協作能力。

5. Commit Message 是工程 evidence

git commit -m "Fix course API validation"

Commit 應描述一組有意義的改動,讓之後 review/rollback 能知道這個 history node 做了什麼。

Project checkpoint:Request Journey Map v14

Local source
  ↓ edit
Working tree
  ↓ stage
Commit
  ↓ push
GitHub main
  ↓ CI
Build/deploy later

Debug evidence:我明明改了,GitHub 為什麼沒有?

  1. git status 有改動嗎?
  2. 有 commit 嗎?
  3. 目前 branch 是哪個?
  4. push 到哪個 remote/branch?
  5. GitHub head SHA 是否一致?

Knowledge check

  1. git add 與 commit 差在哪?
  2. commit 和 push 差在哪?
  3. status/diff/log 各回答什麼問題?
  4. 畫出 local working tree 到 GitHub main 的路徑。