Supplement · Git Engineering · 08-theory-02-index-worktree

HEAD, index và working tree

Staging area là proposed next tree, không chỉ là danh sách file đã chọn.

Ba trạng thái

HEAD biểu diễn snapshot đã commit, index giữ path/mode/object ID cho commit kế tiếp, working tree là file materialized để chỉnh sửa. git diff so worktree với index; git diff --cached so index với HEAD. Một file có thể vừa staged vừa modified.

Index khi merge

Index bình thường có stage 0; conflict có base/ours/theirs ở stages 1/2/3. Resolve nghĩa là tạo đúng content rồi git add để đưa về stage 0. assume-unchangedskip-worktree là performance/working-tree bits, không phải cơ chế bỏ qua thay đổi an toàn.

Reset, restore, checkout

reset di chuyển ref và tùy mode cập nhật index/worktree; restore phục hồi path rõ nguồn; checkout vừa đổi branch vừa phục hồi file nên dễ nhầm. Trước thao tác destructive, đọc status/diff và tạo ref tạm.

Pro Git: Reset Demystified · git-read-tree · git-restore · git-status
← Chương 01Chương 03 →