LEVEL 4 · ระดับเทพ
Repo ใหญ่ & บทสรุป
15.1 เมื่อ repo เริ่มอืด
repo ที่โตมาก (ประวัติยาว ไฟล์เยอะ) จะเริ่มช้า เครื่องมือที่ช่วย:
- shallow clone —
git clone --depth 1ดึงแค่ commit ล่าสุด ไม่เอาประวัติทั้งหมด เหมาะกับ CI ที่ต้องการแค่โค้ดล่าสุด - Git LFS — ไฟล์ใหญ่ที่ไม่ใช่โค้ด (วิดีโอ, โมเดล, รูปความละเอียดสูง) ไม่เหมาะเก็บใน Git ตรง ๆ เพราะทุกเวอร์ชันถูกเก็บครบ LFS เก็บไฟล์จริงแยกที่อื่น เหลือไว้ใน repo แค่ตัวชี้
- git gc — เก็บกวาด object ที่ลอยและบีบอัดเป็น packfile (ปกติ Git ทำเองเป็นระยะ)
15.2 บทสรุปทั้งเล่ม — แก่นที่ถือกลับไป
ถ้าจำได้แค่ไม่กี่อย่างจากทั้งเล่ม ขอให้เป็นสิ่งเหล่านี้ เพราะทุกคำสั่งงอกออกมาจากมัน:
- commit คือ ภาพถ่ายทั้งโปรเจกต์ ที่มี SHA ผูกกับเนื้อหา — จึงแก้ไม่ได้ ปลอมไม่ได้ และเป็นรากของความน่าเชื่อถือทั้งหมด
- ไฟล์เดินทางผ่าน สามพื้นที่ (working → staging → repository) — เข้าใจสิ่งนี้แล้ว add/commit/restore/reset เป็นเรื่องเดียวกันหมด
- branch เป็นแค่ ป้ายชี้ commit — merge, rebase, reset ล้วนคือการขยับป้ายและผูกสายประวัติ
- เกือบทุกอย่าง กู้คืนได้ ถ้าเคย commit —
reflogคือตาข่ายนิรภัย กล้าทดลองได้เต็มที่ - เส้นแบ่งเดียวที่ต้องเคารพ: อย่าเขียนประวัติที่แชร์กับคนอื่นไปแล้ว
— จบหลักสูตร —
รายการอ้างอิง#
เรียงตามลำดับที่ปรากฏครั้งแรกในเล่ม เล่มนี้ไม่ปักรุ่น Git — หน้าเอกสารบน git-scm.com ทุกรายการอ่านจากฉบับล่าสุดตอนตรวจ (Git 2.56.0 · 4 พฤศจิกายน 2026) ถ้าเครื่องคุณใช้รุ่นเก่ากว่า ดูหน้าเดียวกันของรุ่นตัวเองได้ด้วย git help <คำสั่ง> · ทุกรายการเปิดอ่านได้ฟรีทั้งหน้า
- Chacon S, Straub B. Getting Started — What is Git? Pro Git ฉบับที่ 2 (Apress 2014) หัวข้อ 1.3 · git-scm.com/book — บทที่ 1, 2 · ภาพถ่ายไม่ใช่ส่วนต่าง · งานเกือบทุกอย่างทำในเครื่อง · checksum SHA-1 ยาว 40 ตัวอักษรฐานสิบหก
- Git project. git-init — Create an empty Git repository or reinitialize an existing one. เอกสารทางการ Git · git-scm.com/docs/git-init — บทที่ 1, 12 · โครง
.git/(objects·refs/heads·refs/tags) และinit.defaultBranch· ค่าเริ่มต้นยังเป็นmasterและจะเปลี่ยนเป็นmainเมื่อ Git 3.0 ออก - Git project. hash-function-transition (แผนย้ายฟังก์ชันแฮชจาก SHA-1 ไป SHA-256). เอกสารทางการ Git · git-scm.com/docs/hash-function-transition — บทที่ 2, 12 · ชื่อ object แบบ SHA-1 ยาว 40 ตัว แบบ SHA-256 ยาว 64 ตัว
- Git project. git-log — Show commit logs. เอกสารทางการ Git · git-scm.com/docs/git-log — บทที่ 3, 11 ·
--oneline·--graph·-S(pickaxe) ·--grep·--author· ช่วงA..B - Git project. gitignore — Specifies intentionally untracked files to ignore. เอกสารทางการ Git · git-scm.com/docs/gitignore — บทที่ 3 · ไฟล์ที่ติดตามอยู่แล้วไม่ถูกกระทบ และคำแนะนำ
git rm --cached - Chacon S, Straub B. Git Internals — Git References. Pro Git ฉบับที่ 2 (Apress 2014) หัวข้อ 10.3 · git-scm.com/book — บทที่ 4, 12 · branch คือไฟล์ใน
refs/headsที่เก็บ SHA ·HEADเป็น symbolic reference · tag object คือวัตถุชนิดที่สี่ - Git project. git-switch — Switch branches. เอกสารทางการ Git · git-scm.com/docs/git-switch — บทที่ 4, 5 ·
-c·--detach· การเดาสร้าง branch ติดตาม remote เมื่อชื่อตรงกันใน remote เดียว (--guessเป็นค่าเริ่มต้น) - Git project. git-checkout — Switch branches or restore working tree files. เอกสารทางการ Git · git-scm.com/docs/git-checkout — บทที่ 4 · หัวข้อ DETACHED HEAD และการเก็บ commit ที่ทำในสถานะนั้นด้วยการสร้าง branch
- Git project. git-clone — Clone a repository into a new directory. เอกสารทางการ Git · git-scm.com/docs/git-clone — บทที่ 5, 15 · ชื่อ remote เริ่มต้น
originและ--depth(shallow clone) - GitHub. Token authentication requirements for Git operations. The GitHub Blog 15 ธันวาคม 2020 · github.blog — บทที่ 5 · เลิกรับรหัสผ่านบัญชีสำหรับงาน Git ตั้งแต่ 13 สิงหาคม 2021
- GitHub. Generating a new SSH key and adding it to the ssh-agent. GitHub Docs · docs.github.com — บทที่ 5
- Git project. git-pull — Fetch from and integrate with another repository or a local branch. เอกสารทางการ Git · git-scm.com/docs/git-pull — บทที่ 5 · ฉบับปัจจุบันระบุว่าค่าเริ่มต้นคือ
--ff-onlyเมื่อไม่ได้ตั้งpull.rebaseหรือpull.ffถ้าสองฝั่งแยกทางกันแล้วgit pullจะหยุด ไม่ merge ให้เอง — ตั้งค่าหรือระบุ--no-rebase/--rebaseก่อน - Git project. git-push — Update remote refs along with associated objects. เอกสารทางการ Git · git-scm.com/docs/git-push — บทที่ 5, 9, 14 ·
-u· การปฏิเสธ push ที่ไม่ใช่ fast-forward ·--tags/--follow-tags·--force-with-leaseเทียบ--force - Git project. git-reset — Set HEAD or the index to a known state. เอกสารทางการ Git · git-scm.com/docs/git-reset — บทที่ 6 · โหมด
--soft/--mixed(ค่าเริ่มต้น) /--hard - Git project. git-revert — Revert some existing commits. เอกสารทางการ Git · git-scm.com/docs/git-revert — บทที่ 6, 7 · revert บันทึก commit ใหม่ที่กลับผลของ commit เดิม และหน้านี้เตือนว่าทั้ง
reset --hardและrestore --sourceทิ้งการแก้ที่ยังไม่ commit - Git project. git-reflog — Manage reflog information. เอกสารทางการ Git · git-scm.com/docs/git-reflog — บทที่ 7, 14 · ไวยากรณ์
HEAD@{n}และการหมดอายุของ entry - Git project. git-rebase — Reapply commits on top of another base tip. เอกสารทางการ Git · git-scm.com/docs/git-rebase — บทที่ 8 · คำสั่งใน interactive rebase ·
--continue/--skip/--abort· หัวข้อ RECOVERING FROM UPSTREAM REBASE - Chacon S, Straub B. Git Branching — Rebasing. Pro Git ฉบับที่ 2 (Apress 2014) หัวข้อ 3.6 · git-scm.com/book — บทที่ 8, 14 · ช่วง The Perils of Rebasing ที่มาของกฎทอง
- Driessen V. A successful Git branching model. nvie.com 5 มกราคม 2010 (เพิ่ม Note of reflection 5 มีนาคม 2020) · nvie.com — บทที่ 8, 10 · ต้นทางของ Git Flow · บันทึกปี 2020 ของผู้เขียนเองแนะนำ workflow ที่ง่ายกว่าสำหรับทีมที่ส่งมอบต่อเนื่อง
- Git project. git-rerere — Reuse recorded resolution of conflicted merges. เอกสารทางการ Git · git-scm.com/docs/git-rerere — บทที่ 8, 13 · ต้องเปิด
rerere.enabled· rerere เขียนผลลงไฟล์ให้ แต่ไม่แตะ index จึงยังต้องตรวจแล้วgit addเอง - Git project. git-tag — Create, list, delete or verify tags. เอกสารทางการ Git · git-scm.com/docs/git-tag — บทที่ 9 · annotated สำหรับ release · lightweight สำหรับป้ายส่วนตัวหรือชั่วคราว
- Hammant P, with contributions from friends. Trunk Based Development. trunkbaseddevelopment.com · trunkbaseddevelopment.com — บทที่ 10 · branch เดียวชื่อ trunk · feature branch อายุสั้น · feature flag
- Conventional Commits 1.0.0. conventionalcommits.org · conventionalcommits.org — บทที่ 10 · สเปกนิยามแค่
featกับfixส่วนdocs:refactor:เป็นชนิดที่สเปกอนุญาต (ตามแนว commitlint/Angular) - Git project. git-bisect — Use binary search to find the commit that introduced a bug. เอกสารทางการ Git · git-scm.com/docs/git-bisect — บทที่ 11 · บรรทัดจริงของ Git คือ
Bisecting: 675 revisions left to test after this (roughly 10 steps) - Chacon S, Straub B. Git Internals — Git Objects. Pro Git ฉบับที่ 2 (Apress 2014) หัวข้อ 10.2 · git-scm.com/book — บทที่ 12 · content-addressable filesystem · blob / tree / commit · ผล
git cat-file -pของ commit จริงมีทั้งบรรทัด author และ committer - Chacon S, Straub B. Git Internals — Packfiles. Pro Git ฉบับที่ 2 (Apress 2014) หัวข้อ 10.4 · git-scm.com/book — บทที่ 12 · pack เมื่อ loose object เยอะ ตอน
git gcหรือตอน push · เก็บ delta ระหว่างไฟล์ที่คล้ายกัน - Git project. git-worktree — Manage multiple working trees. เอกสารทางการ Git · git-scm.com/docs/git-worktree — บทที่ 13
- Git project. githooks — Hooks used by Git. เอกสารทางการ Git · git-scm.com/docs/githooks — บทที่ 13 ·
pre-commitรันก่อนขอข้อความ commit และ exit ไม่เป็น 0 = ยกเลิก ·commit-msg·pre-push·core.hooksPath - Chacon S, Straub B. Customizing Git — Git Hooks. Pro Git ฉบับที่ 2 (Apress 2014) หัวข้อ 8.3 · git-scm.com/book — บทที่ 13 · hook ฝั่ง client ไม่ถูกคัดลอกไปตอน clone
- Git project. git-sparse-checkout — Reduce your working tree to a subset of tracked files. เอกสารทางการ Git · git-scm.com/docs/git-sparse-checkout — บทที่ 13 · หน้านี้ยังติดป้ายว่าคำสั่งอยู่ในขั้นทดลอง (experimental)
- Git project. git-fsck — Verifies the connectivity and validity of the objects in the database. เอกสารทางการ Git · git-scm.com/docs/git-fsck — บทที่ 14 ·
--lost-foundและความหมายของ dangling object - Git project. git-gc — Cleanup unnecessary files and optimize the local repository. เอกสารทางการ Git · git-scm.com/docs/git-gc — บทที่ 7, 14, 15 ·
gc.reflogExpireค่าเริ่มต้น 90 วัน ·gc.reflogExpireUnreachableค่าเริ่มต้น 30 วัน ·gc --autoที่คำสั่งทั่วไปเรียกเอง - Git project. git-filter-branch — Rewrite branches. เอกสารทางการ Git · git-scm.com/docs/git-filter-branch — บทที่ 14 · คำเตือนต้นหน้าที่ไม่แนะนำให้ใช้ และชี้ไปที่ git filter-repo (ติดตั้งแยก ไม่ได้มากับ Git)
- GitHub. Removing sensitive data from a repository. GitHub Docs · docs.github.com — บทที่ 3, 14 · ขั้นแรกคือเพิกถอนหรือหมุนรหัสลับ แล้วค่อยเขียนประวัติใหม่ด้วย git-filter-repo
- Git LFS project. Git Large File Storage. git-lfs.com · git-lfs.com — บทที่ 15 · แทนไฟล์ใหญ่ด้วย text pointer ใน Git
เล่มต่อไป: git push แล้วเกิดอะไรต่อ?#
ตลอดเล่มนี้ทุกอย่างจบลงที่ git push — งานของคุณขึ้นไปอยู่บนเซิร์ฟเวอร์แล้ว แต่มีคำถามที่ค้างอยู่: ใครเป็นคนตรวจว่าโค้ดที่เพิ่งรวมเข้ามายัง build ได้ เทสต์ผ่าน และไม่ทำของเดิมพัง? ถ้าให้คนนั่งตรวจเองทุกครั้ง ทุกอย่างจะช้าและพลาดง่าย คำตอบคือ CI/CD — การให้เครื่องตรวจและส่งมอบโค้ดอัตโนมัติทุกครั้งที่คุณ push หรือเปิด Pull Request
มันคือก้าวต่อจากตรงนี้พอดี: เหตุการณ์ใน Git ที่คุณเรียนมาทั้งเล่ม (push, PR, tag) คือ "ทริกเกอร์" ที่ปลุกสายการตรวจสอบและ deploy ให้ทำงานเอง
อ่านต่อ: System Design#
เข้าใจกลไกของ Git แล้ว รู้วิธีจัดการโค้ดของทีมให้ปลอดภัยและย้อนกลับได้ — แต่โค้ดที่ push ไปแล้วต้องรันบนระบบที่รับมือกับผู้ใช้จริงได้ System Design พาไปจากคำถาม "จัดการโค้ดยังไง" สู่ "ระบบที่ deploy ไปแล้วต้องออกแบบยังไงให้ scale ได้จริง" ตั้งแต่เซิร์ฟเวอร์เครื่องเดียวไปจนถึง production พร้อม auth และความปลอดภัย · เปิดอ่าน System Design Handbook →
Git 0 → Hero — คู่มือฉบับเข้าใจถึงแก่น · เขียนเป็นภาษาไทย พร้อมไดอะแกรมทุกหัวข้อ
วิธีใช้ให้คุ้ม: อ่านไล่ระดับ อย่าข้าม Level 0–1 แม้จะใช้ Git เป็นแล้ว เพราะแบบจำลองความคิดในบทต้นคือกุญแจของบทท้าย · ลองทุกคำสั่งใน repo ทดลองที่พังได้
If this was useful —buy me a coffeeor PromptPay · Lightning