Branching Exercise

1. สร้างไดเรกทอรี่ใหม่ชื่อ patronus
2. สร้าง git repo ใหม่ในไดเรกทอรี่นี้
3. สร้างไฟล์ใหม่ชื่อ patronus.txt (ในไฟล์เป็นไฟล์ว่างยังไม่ต้องพิมพ์อะไร)
4. ทำการ add และ commit ไฟล์ว่างนี้ด้วยข้อคยาม “add empty patronus file”

รันคำสั่ง `git log` จะแสดงผลดังต่อไปนี้

commit 87df483119e175ea9c44f68349fc0d826db59857 (HEAD -> main)
Author: Mr.Watcharin Sarachai 
Date:   Mon Aug 5 17:18:00 2024 +0700

    add empty patronus file

หมายเหตุ: ค่า hash code อาจไม่เหมือนกัน

5. จากนั้นสร้าง branch ใหม่ชื่อ harry และสร้างอีก branch ชื่อ snape (ทั้งสอง branch แยกออกจาก master branch)
6. ย้ายไป harry branch โดยใช้คำสั่งใหม่ “switch” ในการเปลี่ยน branches
7. ในไฟล์ patronus.txt เพิ่มข้อความดังต่อไปนี้:

HARRY'S PATRONUS
       /|       |\
    `__\\       //__'
       ||      ||
     \__`\     |'__/
       `_\\   //_'
       _.,:---;,._
       \_:     :_/
         |@. .@|
         |     |
         ,\.-./ \
         ;;`-'   `---__________-----.-.
         ;;;                         \_\
         ';;;                         |
          ;    |                      ;
           \   \     \        |      /
            \_, \    /        \     |\
              |';|  |,,,,,,,,/ \    \ \_
              |  |  |           \   /   |
              \  \  |           |  / \  |
               | || |           | |   | |
               | || |           | |   | |
               | || |           | |   | |
               |_||_|           |_|   |_|
               /_//_/           /_/   /_/
    

8. ทำการ add และ commit การแก้ไขนี้โดยใช้ข้อความ “add harry’s stag patronus”
9. ย้ายไปยัง snape branch ใช้คำสั่งเก่า “checkout” ในการเปลี่ยน branches
10. กรอกข้อความดังต่อไปนี้ไปในไฟล์ patronus.txt:

SNAPE'S PATRONUS
                   .      _,
                   |`\__/ /
                   \  . .(
                    | __T|
                   /   |
      _.---======='    |
     //               {}
    `|      ,   ,     {}
     \      /___;    ,'
      ) ,-;`    `\  //
     | / (        ;||
     ||`\\        |||
     ||  \\       |||
     )\   )\      )||
     `"   `"      `""

11. ทำการ add และ commit การเปลี่ยนแปลงบน snape branch ด้วยข้อความ “add snape’s doe patronus”
12. ขั้นตอนต่อไปสร้าง branch ใหม่แยกจาก snape branch ชื่อ lily
13. ย้ายไปยัง lily branch
14. แก้ไขไฟล์ patronus.txt โดยเปลี่ยนจากข้อความ SNAPE’S PATRONUS ให้เป็น LILY’S PATRONUS (ส่วนที่เหลือไม่ต้องแก้ไข)
15. ทำการ add และ commit การแก้ไขนี้ด้วยข้อความ “add lily’s doe patronus”
16. รันคำสั่ง git เพื่อแสดงรายชื่อทุก branches (เราจะต้องเห็นทั้งหมด 4 branches) หรือเปิดโปรแกรม Gitkraken จะเห็น branch ดังแสดงในรูปต่อไปนี้

17. ทดสอบไปยัง branch ต่าง ๆ สังเกตุการเปลี่ยนแปลงในไฟล์ patronus.txt

18. Bonus: ให้ลบ (delete) snape branch (poor Snape)

อ.ดร.วัชรินทร์ สาระไชย
อ.ดร.วัชรินทร์ สาระไชย

Hello! I’m Watcharin Sarachai, an enthusiastic and dedicated educator with a passion for advancing the field of computer science. I hold a Ph.D. in Computer Science from Chiang Mai University, where I focused on cutting-edge research in Machine Learning, Computer Programming, and Embedded Systems.

Articles: 19