ชีตเช็คคำสั่ง Git

Git ติดตามการเปลี่ยนแปลงไฟล์ของคุณเป็นชุดของคอมมิทในรีโพซิทอรี คำสั่งเหล่านี้ครอบคลุมขั้นตอนประจำวัน: สร้างรีโพ, บันทึกงาน, แตกสาขา, รวม และแชร์กับรีโมต ระหว่างที่เรียนให้เปิดชีตนี้ไว้

อัปเดต:

คำสั่งทำอะไร
git initCreate a new, empty Git repository in the current directory.
git cloneDownload a remote repository and its full history to your machine.
git statusShow changed, staged and untracked files in the working tree.
git addStage changes (files) to be included in the next commit.
git commitRecord staged changes as a new commit with a message.
git logDisplay the commit history of the repository.
git diffShow unstaged or staged differences between states.
git branchList, create or delete branches in the repository.
git checkout / switchSwitch branches or restore files (switch is the modern command).
git mergeJoin another branch's history into the current branch.
git rebaseReapply commits on top of another base commit, rewriting history.
git pullFetch from a remote and merge the changes into the current branch.
git pushUpload local commits to a remote repository.
git stashTemporarily shelve uncommitted changes to reapply later.
git remoteManage the set of remote repositories you track.

หมายเหตุ

คำถามที่พบบ่อย

ความต่างระหว่าง merge และ rebase คืออะไร?
Merge รวมประวัติด้วยคอมมิทใหม่ที่มีสองผู้ปกครอง ส่วน Rebase เล่นคอมมิทของคุณทับบนอีกสาขาหนึ่ง สร้างประวัติแบบเส้นตรงแต่จะเขียนรหัสคอมมิทใหม่
จะยกเลิกคอมมิทอย่างไร?
ใช้ 'git revert <commit>' เพื่อเพิ่มคอมมิทใหม่ที่ยกเลิกการเปลี่ยนแปลง (ปลอดภัย รักษาประวัติร่วม) 'git reset' จะเขียนประวัติใหม่ จึงไม่ควรใช้บนสาขาแชร์
ความต่างระหว่าง git pull และ git fetch คืออะไร?
Fetch ดาวน์โหลดคอมมิทและการอ้างอิงจากรีโมตโดยไม่แตะต้นไม้การทำงาน Pull ทำ fetch แล้วจึง merge หรือ rebase การเปลี่ยนแปลงนั้นเข้าสาขาปัจจุบัน
เมื่อไหร่ควรใช้ git stash?
Stash เก็บการเปลี่ยนแปลงที่ยังไม่คอมมิทชั่วคราว เพื่อให้คุณสลับสาขาหรือดึงโค้ดได้สะอาด แล้วคืนค่าด้วย 'git stash pop' ภายหลัง