Skip to content

การเปลี่ยนแปลงไฟล์ (Change)

เมื่อคุณแก้ไข เพิ่ม หรือลบไฟล์ในโปรเจกต์ Git จะตรวจจับการเปลี่ยนแปลงเหล่านี้โดยอัตโนมัติ

ประเภทของการเปลี่ยนแปลงไฟล์

  • Untracked: ไฟล์ใหม่ที่ยังไม่ถูก add
  • Modified: ไฟล์ที่ถูกแก้ไขแต่ยังไม่ได้ add
  • Deleted: ไฟล์ที่ถูกลบออก

ตัวอย่างสถานการณ์

  • เพิ่มไฟล์ใหม่: สร้างไฟล์ about.html
  • แก้ไขไฟล์: แก้ไขเนื้อหาใน index.html
  • ลบไฟล์: ลบไฟล์ old.txt

ตัวอย่างคำสั่งและผลลัพธ์

ดูรายการไฟล์ที่เปลี่ยนแปลง:

bash
git status

ตัวอย่าง output:

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        about.html

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
        modified:   index.html
        deleted:    old.txt

ข้อควรระวัง

  • อย่าลืม add ไฟล์ใหม่ก่อน commit ไม่เช่นนั้นจะไม่ถูกบันทึกในประวัติ
  • ใช้ git status เพื่อตรวจสอบทุกครั้งก่อน commit