課程網 Course site

通識課共用 · Git 入門 · 坐下先做五分鐘

從建檔到 commit

用滑鼠走一遍:一個檔案怎麼從「剛建好」,一步步變成「存進版本歷史」。 這一頁是模擬的,沒有真的程式在跑,按錯也不會弄壞任何東西。 你不用背指令,只要看得懂每一步發生了什麼。

General education · Git basics · Start here: five minutes

From new file to commit

Click through it once: how one file goes from just created to saved in the version history. This page is a simulation. No real program is running, and nothing you click here can break anything. You do not need to memorise commands. You only need to see what happens at each step.

工作區 working directory

你的桌面。檔案在這裡被建立、被修改,就是你平常在資料夾裡看到的那些檔。

暫存區 staging area

出貨前的紙箱。你決定「這一版要收哪些內容」,先放進來排好,還沒封箱。

版本庫 repository,簡稱 repo

檔案櫃。每 commit 一次就多一格抽屜,裡面是那一刻的完整快照,附時間和說明。

Working directory 工作區

Your desk. Files are created and edited here — the ones you normally see when you open the folder.

Staging area 暫存區

The box before shipping. You decide what goes into the next version and line it up here. The box is not sealed yet.

Repository 版本庫,簡稱 repo

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. 1建檔Create
  2. 2看現況Status
  3. 3放進暫存區Stage
  4. 4存成版本Commit
  5. 5修改Edit
  6. 6看差異Diff
  7. 7再存一版Commit again
  8. 8翻歷史History
工作區 你的桌面Working directory your desk
暫存區 出貨前的紙箱Staging area the box before shipping
版本庫 檔案櫃Repository the filing cabinet

現在發生了什麼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.

一張表記住

一個檔案在 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.

StateWhat you just didWhat Git meansWhat 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

走完了嗎?考自己一下Finished the walkthrough? Test yourself