สูตรโกง Git
สรุปคำสั่ง Git ค้นหาได้ตามหมวด ตั้งแต่ branch และ merge ไปจนถึง rebase, stash และ reset แต่ละคำสั่งบอกวิธีใช้และระดับความเสี่ยง ใช้ฟรี
ตั้งค่า
git config --global user.name "Name"ตั้งชื่อผู้ใช้
git config --global user.name "Sam"
git config --global user.email "email"ตั้งค่าอีเมล
git config --global user.email "[email protected]"
git config --listแสดงการตั้งค่าทั้งหมด
git config --list
เริ่มต้น
git initเริ่มต้นรีโพใหม่
git init my-project
git clone <url>โคลนรีโพจากรีโมต
git clone https://github.com/user/repo.git
การเปลี่ยนแปลง
git statusสถานะไดเรกทอรีทำงาน
git status
git diffเปรียบเทียบการเปลี่ยนแปลง
git diff HEAD~1
git add <file>เพิ่มเข้า staging
git add . / git add file.txt
git commit -m "message"สร้างคอมมิต
git commit -m "feat: new feature"
git commit --amendแก้ไขคอมมิตล่าสุด
git commit --amend -m "updated message"
git stashพักการเปลี่ยนแปลงชั่วคราว
git stash / git stash pop
แบรนช์
git branchแสดงรายการแบรนช์
git branch -a
git branch <name>สร้างแบรนช์ใหม่
git branch feature/login
git checkout <branch>สลับแบรนช์
git checkout main
git checkout -b <name>สร้างแล้วสลับไป
git checkout -b feature/login
git merge <branch>รวมแบรนช์
git merge feature/login
git branch -d <name>ลบแบรนช์
git branch -d feature/login
git branch -D <name>บังคับลบแบรนช์
git branch -D feature/login
รีโมต
git remote -vแสดงรายการรีโมต
git remote -v
git fetchดึงการเปลี่ยนแปลงจากรีโมต
git fetch origin
git pullดึงแล้วรวม
git pull origin main
git pushพุชขึ้นรีโมต
git push origin main
git push --forceบังคับพุช
git push --force origin main
ย้อนกลับ
git restore <file>ทิ้งการเปลี่ยนแปลงของไฟล์
git restore file.txt
git reset HEAD <file>นำไฟล์ออกจาก staging
git reset HEAD file.txt
git revert <commit>ย้อนคอมมิต (สร้างคอมมิตใหม่)
git revert abc123
git reset --soft HEAD~1ย้อนคอมมิตล่าสุด (เก็บการเปลี่ยนแปลง)
git reset --soft HEAD~1
git reset --hard HEAD~1ลบคอมมิตล่าสุด (ทิ้งการเปลี่ยนแปลง)
git reset --hard HEAD~1
ตรวจสอบ
git logประวัติคอมมิต
git log --oneline --graph
git log --onelineประวัติแบบบรรทัดเดียว
git log --oneline -10
git show <commit>รายละเอียดคอมมิต
git show abc123
git blame <file>ผู้เขียนแต่ละบรรทัด
git blame file.txt
git reflogประวัติ HEAD (สำหรับกู้คืน)
git reflog
ฝัง
สูตรโกง Git คืออะไร?
สรุปคำสั่ง Git ค้นหาได้ตามหมวด ตั้งแต่ branch และ merge ไปจนถึง rebase, stash และ reset แต่ละคำสั่งบอกวิธีใช้และระดับความเสี่ยง ใช้ฟรี
วิธีใช้งาน
- 1ป้อนข้อมูล— ป้อนข้อมูลที่ต้องการ
- 2ผลลัพธ์— ตรวจสอบผลลัพธ์ที่ประมวลผล
- 3คัดลอก— คัดลอกผลลัพธ์ไปใช้งาน
เครื่องมือที่เกี่ยวข้อง
คำถามที่พบบ่อย
ใช่ ทำงานแบบออฟไลน์ได้เพราะใช้ข้อมูลแบบคงที่