Initialization and Setup
คำสั่ง | คำอธิบาย |
---|---|
git init | ทำให้สามารถใช้งาน git ได้ |
git config | กำหนดค่าใน .gitconfig |
git ignore | ทำให้ไฟล์นั้นใช้ git ไมได้ |
git prune |
Commit Management
ข้อควรรู้
HEAD => คือ current commit ที่กำลังทำงานอยู่
คำสั่ง | คำอธิบาย |
---|---|
git commit | บันทึกการเปลี่ยนแปลง |
git squash | รวมหลาย commit เข้าด้วยกัน (ผ่าน rebase ) |
git revert | ย้อนกลับการเปลี่ยนแปลงจาก commit โดยการสร้าง commit ใหม่ที่ทำให้การเปลี่ยนแปลงนั้นหายไป |
git reset | ย้าย current commit(HEAD) ไปยัง other commit |
git cherry-pick | นำ commit จาก branch อื่นมารวมใน branch ปัจจุบัน |
git stash | เก็บการเปลี่ยนแปลงที่ยังไม่ได้ commit ไว้ชั่วคราว |
git reflog | ดูประวัติการเคลื่อนไหวของ HEAD |
Branch Management
คำสั่ง | คำอธิบาย |
---|---|
git branch | แสดงรายการ branch หรือสร้าง branch ใหม่ |
git worktree | จัดการกับ worktree ที่แยกจาก repository หลัก |
git checkout | เปลี่ยนไปยัง branch อื่น หรือย้อนกลับไฟล์ที่เปลี่ยนแปลง |
git merge | รวมการเปลี่ยนแปลงจาก branch อื่นเข้ากับ branch ปัจจุบัน |
git rebase | ย้ายหรือรวม commit จาก branch หนึ่งไปยังอีก branch หนึ่ง |
git tag | สร้างหรือแสดง tags ซึ่งเป็นจุดอ้างอิงในประวัติ commit |
git show | |
git log | |
git blame |
Remote Management
คำสั่ง | คำอธิบาย |
---|---|
git remote | จัดการกับ remote repositories เช่น เพิ่ม ลบ หรือแสดง remote |
git pull | ดึงการเปลี่ยนแปลงจาก remote repository และ merge เข้ากับ branch ปัจจุบัน |
git push | ส่งการเปลี่ยนแปลงจาก local repository ไปยัง remote repository |
git fetch | ดึงการเปลี่ยนแปลงจาก remote repository โดยไม่ทำการ merge |
git clone | คัดลอก repository ทั้งหมดจาก remote repository มายังเครื่องของคุณ |
Submodules
คำสั่ง | คำอธิบาย |
---|---|
git submodule | จัดการกับ submodules ซึ่งเป็น repository ที่ฝังอยู่ใน repository หลัก |
git prune | ลบการอ้างอิงที่ไม่มีการใช้งานใน repository |
Other Commands
คำสั่ง | คำอธิบาย |
---|---|
git log | แสดงประวัติ commit |
git blame | แสดงข้อมูลเกี่ยวกับการเปลี่ยนแปลงในแต่ละบรรทัดของไฟล์ |