SYSTEM FOUNDATIONS · 14
Git / GitHub:把「現在的檔案」變成可追蹤歷史
Git 是版本控制系統;GitHub 是託管 Git repository 與協作/CI 的平台。你要先理解 working tree → staging → commit → remote,而不是只背 push/pull 指令。
Learning outcomes
- 能區分 working tree、staging area、commit、remote。
- 能解釋 commit 是 snapshot/history node,不是「上傳」。
- 能讀 status/log/diff 的 evidence。
- 能描述 push/pull 和 GitHub 的角色。
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 -5Diff 告訴你「改了什麼」,log 告訴你「歷史長什麼樣」。
4. Remote / GitHub
local commits
↓ git push
origin/main on GitHub
remote commits
↓ git fetch / pull
local repositoryGitHub 不是 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 laterDebug evidence:我明明改了,GitHub 為什麼沒有?
git status有改動嗎?- 有 commit 嗎?
- 目前 branch 是哪個?
- push 到哪個 remote/branch?
- GitHub head SHA 是否一致?
Knowledge check
- git add 與 commit 差在哪?
- commit 和 push 差在哪?
- status/diff/log 各回答什麼問題?
- 畫出 local working tree 到 GitHub main 的路徑。