Git ระดับกลาง
George Boorman
Curriculum Manager, DataCamp
| คำสั่ง | ฟังก์ชัน |
|---|---|
git diff |
แสดงการเปลี่ยนแปลงระหว่างไฟล์ที่ยังไม่ได้ stage ทั้งหมดกับ commit ล่าสุด |
git diff report.md |
แสดงการเปลี่ยนแปลงระหว่างไฟล์ที่ยังไม่ได้ stage กับ commit ล่าสุด |
git diff --staged |
แสดงการเปลี่ยนแปลงระหว่างไฟล์ที่ stage แล้วทั้งหมดกับ commit ล่าสุด |
git diff --staged report.md |
แสดงการเปลี่ยนแปลงระหว่างไฟล์ที่ stage แล้วกับ commit ล่าสุด |
git diff 35f4b4d 186398f |
แสดงการเปลี่ยนแปลงระหว่าง commit สองรายการโดยใช้ hash |
git diff HEAD~1 HEAD~2 |
แสดงการเปลี่ยนแปลงระหว่าง commit สองรายการโดยใช้ HEAD แทน commit hash |
git diff main summary-statistics


space เพื่อเลื่อนดู และ q เพื่อออกgit branch
main
* feature_dev
feature_dev
ต้องการ branch ใหม่อีกอันสำหรับฟีเจอร์ที่สองที่กำลังพัฒนา
วิธีแก้ — เปลี่ยนชื่อ feature_dev
การเปลี่ยนชื่อ branch
git branch -m
git branch
main
* feature_dev
feature_dev
ต้องการ branch ใหม่อีกอันสำหรับฟีเจอร์ที่สองที่กำลังพัฒนา
วิธีแก้ — เปลี่ยนชื่อ feature_dev
git branch -m feature_dev chatbot
git branch
main
* chatbot
โปรเจกต์ขนาดใหญ่อาจมี branch จำนวนมาก
ลบ branch เมื่อใช้งานเสร็จแล้ว
ลบ branch chatbot ด้วย flag -d
git branch -d chatbot
Deleted branch chatbot (was 3edb989).
chatbot ยังไม่ได้ถูก merge เข้า main คำสั่ง git branch -d chatbot จะเกิดข้อผิดพลาดerror: The branch 'chatbot' is not fully merged.
If you are sure you want to delete it, run 'git branch -D chatbot'.
-Dgit branch -D chatbot
Deleted branch chatbot (was 3edb989).
การกู้คืน branch ที่ลบไปแล้วทำได้ยาก แต่ไม่ใช่ว่าเป็นไปไม่ได้
ตรวจสอบให้แน่ใจว่าไม่ต้องการ branch นั้นอีกแล้วก่อนลบ!
| คำสั่ง | ฟังก์ชัน |
|---|---|
git diff main chatbot |
เปรียบเทียบสถานะของ branch main และ chatbot |
git branch |
แสดงรายการ branch ทั้งหมด |
git branch -m old_name new_name |
เปลี่ยนชื่อ branch จาก old_name เป็น new_name |
git branch -d chatbot |
ลบ branch chatbot ที่ ได้ merge แล้ว |
git branch -D chatbot |
ลบ branch chatbot ที่ ยังไม่ ได้ merge |
Git ระดับกลาง