跳轉至

建立 2024-01-01 更新 2026-09-15

git add

git add 把檔案從 workspace 放進 staging(暫存區),等於告訴 Git:「下一次 commit 要包含這些變更」。沒有 add 的修改不會進版本歷史。

基本用法

git add <檔案名稱>

常用範例

加入單一檔案:

git add index.html

加入多個檔案:

git add index.html style.css app.js

加入目前目錄底下所有變更(含新檔):

git add .

養成習慣:提交前用 git status 看暫存區裡有沒有不該進去的檔。

影響的區域

workspace → staging。內容還在工作區,只是多標記「這批要提交」。

從暫存區拿掉

還沒 commit 之前,可以取消 add,檔案本身不會被刪:

git restore --staged <檔案名稱>

常見搭配

git status
git commit -m "說明這次變更"