DEV Community

uuunaja for Ookbee

Posted on

5 1

Semantic Commit Messages

ปัญหาของ commit message

โดยปกติแล้ว เวลาเรา commit code เข้า source control ถ้าไม่ได้มีการตกลงกันว่าจะใช้ commit message รูปแบบไหน ก็จะออกมาแนวตัวอย่างด้านล่าง

13be475b2 - 3 weeks ago : change tutorial banner
0559f19c6 - 3 weeks ago : Add hours ago for unlockerView
31f7893eb - 3 weeks ago : Fix barrier constraint
ba2a7b935 - 3 weeks ago : Update build version

จะเห็นได้ว่าอ่านได้ยากพอสมควร เนื่องจากแต่ละ message ไม่มีความชัดเจนว่าเป็นงานแบบไหน จึงควรมี format ที่เป็นตัวกลางสักตัวที่ทุกคนในทีมเวลา commit code จะได้เขียนเหมือนๆ กัน

Semantic Commit Messages

ข้างล่างนี้จะเป็นรูปแบบของ message ที่ชื่อว่า Semantic Commit Messages

ความหมาย

  • feat: feature ใหม่สำหรับผู้ใช้ เช่น เพิ่มให้ผู้ใช้เซฟรูปภาพลงเครื่องได้
  • fix: แก้บั๊กต่างๆ ก็เขียนแปะไว้ว่าที่เราแก้ไปมีบั๊กเรื่องอะไรบ้าง
  • doc: ใช้สำหรับอัพเดทพวก document ประกอบ ใน git เราสามารถใส่ document ของ project เราลงไปได้เช่นพวก README.md
  • style: แก้พวก code style พวก spacebar ลืม semicolons หรือปรับ format ต่างของ code ที่ไม่กระทบกับการใช้งานของผู้ใช้
  • refactor: refactor code รวมถึงเรื่องเปลี่ยนชื่อ function หรือตัวแปรต่างๆ
  • test: ใช้เวลาแก้ code ในระบบ test ที่ไม่กระทบการใช้งานของผู้ใช้ เช่น เพิ่ม test หรือ refactor test
  • chore: แก้ไข build script ต่างๆ ที่ไม่เกี่ยวกับตัว source code

โดยหลังจากเปลี่ยนแล้วไปใช้ format เดียวกันแล้วตาม comment ตัวอย่างข้างบนเราจะได้ออกมาตามด้านล่างนี้

13be475b2 - 3 weeks ago : feat: change tutorial banner
0559f19c6 - 3 weeks ago : style: Add hours ago for unlockerView
31f7893eb - 3 weeks ago : fix: barrier constraint
ba2a7b935 - 3 weeks ago : chore: Update build version

สรุป

การที่เราใส่ commit message ให้เป็นไปตามรูปแบบที่ตกลงกันไว้ เวลาเราย้อนกลับมาดูหรือเวลา review code กัน มันช่วยให้ทีมสื่อสารกันได้ง่ายขึ้น จะมาหาอะไรเราก็สนใจที่หัวข้อก่อนได้เลย

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more