你的桌面。檔案在這裡被建立、被修改,就是你平常在資料夾裡看到的那些檔。
出貨前的紙箱。你決定「這一版要收哪些內容」,先放進來排好,還沒封箱。
檔案櫃。每 commit 一次就多一格抽屜,裡面是那一刻的完整快照,附時間和說明。
Your desk. Files are created and edited here — the ones you normally see when you open the folder.
The box before shipping. You decide what goes into the next version and line it up here. The box is not sealed yet.
The filing cabinet. Each commit adds one drawer holding a complete snapshot of that moment, with a time and a note.
練習台:一個檔案的第一趟旅程Practice bench: one file’s first journey
下面的按鈕一次只會亮該做的那一顆,照著按就好。Only the button you should press next lights up. Just follow them.
- 1建檔Create
- 2看現況Status
- 3放進暫存區Stage
- 4存成版本Commit
- 5修改Edit
- 6看差異Diff
- 7再存一版Commit again
- 8翻歷史History
現在發生了什麼What just happened
背後其實是這幾行指令The commands behind it
你不必自己打。跟 AI 一起工作時,這些是它替你敲的;你的工作是看懂它回報了什麼。You do not have to type these. When you work with AI, these are the lines it runs for you; your job is to understand what it reports back.
寫「為什麼改」,不是只寫檔名。三個月後的你看到「update」會完全想不起來改了什麼。Write why you changed it, not just the file name. Three months from now, “update” will tell you nothing.
一張表記住
一個檔案在 Git 眼裡只有四種狀態
剛才那趟旅程,其實就是在這四格之間移動。看到 Git 回報哪個字,就知道自己在哪一格、下一步該做什麼。
| 狀態 | 你剛做了什麼 | Git 的意思是 | 下一步通常是 |
|---|---|---|---|
| 未追蹤untracked | 新建了一個檔 | 「有個新檔案,我還沒開始管它」 | 放進暫存區(add) |
| 已修改modified | 改了一個已經有版本的檔 | 「這個檔跟最新一版長得不一樣」 | 先看差異(diff),確認沒改錯,再 add |
| 已暫存staged | 按了 add | 「下一版會收這些內容」 | 存成版本(commit) |
| 乾淨clean / committed | 按了 commit | 「桌面跟最新一版一模一樣,沒事」 | 繼續工作;要備份到 GitHub 就 push |
One table to remember
In Git’s eyes a file has only four states
That whole journey was just moving between these four boxes. Once you know which word Git reports, you know where you are and what usually comes next.
| State | What you just did | What Git means | What usually comes next |
|---|---|---|---|
| untracked未追蹤 | You created a new file | “There is a new file here, but Git is not tracking it yet” | Put it in the staging area (add) |
| modified已修改 | You edited a file that already has a version | “This file is not the same as the latest version” | Read the diff first, check it is what you wanted, then add |
| staged已暫存 | You pressed add | “The next version will include this content” | Save the version (commit) |
| clean / committed乾淨 | You pressed commit | “Your desk matches the latest version. Nothing pending” | Carry on working; to back it up on GitHub, push |
最常搞混的五件事
這些不是同一件事
存檔(Ctrl+S)= commit?不是。
存檔只是把內容寫進硬碟。Git 要等你 commit,才會替這一刻留下一版。
add = 上傳?不是。
add 只是把內容放進紙箱,什麼都還沒送出去,連版本都還沒建立。
commit = 上傳到 GitHub?也不是。
commit 存在你這台電腦的版本庫裡。要送到 GitHub,還要再做一步 push。這一頁沒講 push,因為它是另一趟旅程。
之後改了檔,舊版就沒了?不會。
每一個 commit 都留著。你隨時可以翻回去看任何一版長什麼樣,這正是版本控制的價值。
add 之後再改檔,commit 會收最新的?不會。
紙箱裡裝的是你按 add 那一刻的內容。之後的修改要再 add 一次才會進去。練習台最後有個小實驗可以親眼看。
The five things people mix up most
These are not the same thing
Does saving the file (Ctrl+S) create a commit? No.
Saving only writes the content to disk. Git keeps a version of this moment only when you commit.
Does add mean upload? No.
add only puts the content in the box. Nothing has been sent anywhere, and no version exists yet.
Does a commit upload the file to GitHub? Also no.
A commit is stored in the repository on your own computer. Getting it to GitHub takes one more step, push. This page does not cover push, because that is another journey.
Once you edit the file, is the old version gone? No.
Every commit stays. You can go back and read any version at any time, and that is exactly what version control is for.
If you edit after add, does commit take the newest content? No.
The box holds what you put in at the moment you pressed add. Later edits go in only if you add again. There is a small experiment at the end of the practice bench where you can watch it happen.
四題自我檢查Four questions to check yourself