DEV Community

c_nooknook_daily_prompt
c_nooknook_daily_prompt

Posted on

3 ขั้นตอนเขียน Pattern Commit แบบ Conversation อย่างมืออาชีพ

ขั้นตอนที่ 1: เริ่มจากคำถามตัวเอง – “Commit นี้ทำอะไร?”
พยายามตอบคำถามนี้ให้ชัดแบบสั้น ๆ ในใจคุณก่อน commit

ตัวอย่าง:
“ฉันเพิ่มฟีเจอร์ลบบัญชีผู้ใช้จากเบอร์มือถือ”
“ฉันแก้ logic ที่ผิดในฟังก์ชัน delete”
“ฉันเพิ่ม unit test สำหรับ service deleteByMobile”

ขั้นตอนที่ 2: แยกออกเป็น 3 ส่วนของ Conventional Commit

Conventional Commits Pattern

<type>(<scope>): <short summary>

[optional body]

[optional footer(s)]
Enter fullscreen mode Exit fullscreen mode
ส่วน ใช้ทำอะไร ตัวอย่าง
<type> ประเภทของการเปลี่ยนแปลง feat, fix, refactor, test, docs, chore
<scope> ส่วนของระบบ/ไฟล์/โมดูล ที่เปลี่ยน member, auth, payment, api, controller
short description อธิบายสิ่งที่ทำ add deleteByMobile, fix logic, add test

Type

ประเภท ใช้เมื่อ...
feat เพิ่มฟีเจอร์ใหม่ (feature)
fix แก้บั๊ก (bug fix)
docs แก้ไขเอกสาร เช่น README.md
style ปรับ formatting, white-space, semicolon ฯลฯ
refactor เปลี่ยนโค้ดโดยไม่เปลี่ยน behavior
perf ปรับ performance ให้ดีขึ้น
test เพิ่มหรือแก้ไขเทสต์ (unit/integration)
chore งานเบ็ดเตล็ด เช่น อัปเดต dependency
ci การปรับ CI/CD pipeline
build เปลี่ยน build process หรือ dependency ที่ใช้ build
revert ย้อนกลับ commit ก่อนหน้า

ขั้นตอนที่ 3: ประกอบร่าง Commit Message

อธิบาย:

  • fix → เพราะคุณแก้ logic
  • (member) → scope คือโมดูล member
  • update deleteByMobile logic and add service test → บอกว่าแก้ logic และเพิ่ม test

เคล็ดลับเสริมแบบมือโปร

สถานการณ์ Commit message
เริ่มต้นโปรเจกต์ chore(init): initial project setup
แก้บั๊ก fix(auth): fix login error on Safari
เพิ่มฟีเจอร์ใหม่ feat(user): add reset password feature
เพิ่ม test test(member): add unit test for deleteByMobile
ปรับโครงสร้างไม่เปลี่ยน behavior refactor(order): move validation logic to helper
อัปเดตเอกสาร docs(readme): update usage instructions

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.