Committing Code
![Committing Code](/_next/image?url=https%3A%2F%2Fsennalabs.s3.ap-southeast-1.amazonaws.com%2Fblogs%2FCommittingCodeByPae_1705984697054.png&w=3840&q=75)
ในปัจจุบันสำหรับชาว Dev นั้น Version Control ได้เข้ามามีบทบาทอย่างมากในการ Manage Source Code ของเรา และในแต่ละวันเราคงใช้ Git กันเป็นประจำอยู่แล้วในการเก็บ Source Code ของเรา แต่เพื่อน ๆ ชาว Dev ทราบกันหรือเปล่าว่าการ Commit Message สามารถทำให้ทีมเราหรือเราเองสามารถที่จะ Review Code ได้ง่ายขึ้น และในการเก็บ Commit เป็นระเบียบมากขึ้น ในบทความนี้เราจะมาเจาะลึกเกี่ยวกับการเขียน Commit Message กัน
ทำไม Commit Message ของ Git ถึงสำคัญ ?
-
Documentation
Commit Message จะถูกเก็บเป็นประวัติไว้ใน Version Control การที่เราทำให้ Commit Message เข้าใจง่ายและอ่านง่าย เราก็จะสามารถที่จะหาสิ่งที่เราต้องการหาได้ง่ายขึ่้น -
Collaboration
ในการทำงานเป็นทีม Commit Message ที่ดีจะช่วยทำให้ทีมมีการสื่อสารที่มีประสิทธิภาพมากขึ้น การที่ Commit Message ชัดเจนเข้าใจง่าย จะช่วยให้เพื่อนร่วมทีมเข้าใจว่ามีอะไรเปลี่ยนแปลงมาบ้างโดยที่ไม่ต้องใช้เวลาทำความเข้าใจเยอะ และยังช่วยเรื่องของการ Review Code ได้อีกด้วย -
Troubleshooting
Commit Message ที่ดีนั้นจะทำให้หา Bug หรือ Defect ต่าง ๆ ได้ง่ายขึ้น
Best Practice for Writing Git Commit Message
-
Be clear and concise
ควรใช้ข้อความที่สั้นกระชับและเข้าใจง่าย เน้นสรุปด้วยประโยคเดียวที่บอกว่าอะไรมีการเปลี่ยนแปลงใน Commit นั้น ๆ
-
Use the imperative mood
ควรใช้คำขึ้นต้น Commit ด้วยคำกริยา เช่น Add, Fix, Update และ Refactor เพื่อเป็นความหมายหลักในการบอกว่า Commit นั้น ๆ เราทำอะไรเป็นหลัก -
Include the “Why”
บอกว่าอะไร ทำไม ถึงเปลี่ยนแปลง เพื่อให้ง่ายต่อการทำความเข้าใจ -
Follow the team
ทำตามรูปแบบที่กำหนดของทีมเพื่อให้ Commit Message ไปในทางเดียวกัน
Subject Line Standard Terminology from Git
![](https://sennalabs.s3.ap-southeast-1.amazonaws.com/blogs/Screenshot2567-01-23at11_1705984146575.png)
![](https://sennalabs.s3.ap-southeast-1.amazonaws.com/blogs/Screenshot2567-01-23at11_1705984161306.png)
ตัวอย่าง
Good Commit Message
-
Fix authentication bug for user login
-
Fix the issue with user authentication
-
Add login button to login page
-
Update the dependency version to address security vulnerabilities
-
Refactor database schema to improve performance
-
Release version 1.0.0
-
Remove deprecated methods
-
Update getting started documentation
นี่คือตัวอย่างของ Commit Message ที่ดี ต่อมาเราไปดู Commit Message ที่ไม่ควรใช้กันบ้าง
Bad Commit Message
-
Fixed bug with Y
-
Changing behavior of X
-
Add C
สรุป
ในโลกของการพัฒนาซอฟต์แวร์ การที่ทำให้การทำงานร่วมกันและการสื่อสารที่ชัดเจนเป็นสิ่งสำคัญ การเรียนรู้การเขียน Commit Message ของ Git เป็นทักษะที่ชาว Dev อย่างเรา ๆ ควรฝึกฝนและหัดเขียนให้เป็นนิสัย เพราะในการทำงานเป็นทีมหรือทำงานจริง ๆ แล้ว อะไรที่ทำให้เข้าใจง่ายจะทำให้การสื่อสารในทีมดีขึ้น และจะช่วยเพิ่มประสิทธิภาพการทำงานเป็นทีมได้ดีขึ้น สำหรับมือใหม่แล้วในตอนนี้เราอาจจะไม่ค่อยเห็นภาพมาก แต่ถ้าวันนึงเรามีโอกาสได้ไปทำงานร่วมกับทีมที่ทำ Project เยอะ ๆ Commit เราอาจจะเห็นภาพมากขึ้นก็ได้นะ Enjoy coding :>
![Pae Flutter](/_next/image?url=https%3A%2F%2Fsennalabs.s3.ap-southeast-1.amazonaws.com%2Fteams%2FBG_29-Paedev_1679438843634.png&w=3840&q=75)
![](/_next/image?url=%2Fimages%2Fsubscribe.webp&w=3840&q=75)
Subscribe to follow product news, latest in technology, solutions, and updates
Other articles for you
Let’s build digital products that are simply awesome !
We will get back to you within 24 hours!Go to contact us![](/_next/image?url=%2Fimages%2Ftell-us-arrow.webp&w=384&q=75)
![Contact ball](/_next/image?url=%2Fimages%2Fcontact-ball.webp&w=3840&q=75)
![Contact us bg 2](/_next/image?url=%2Fimages%2Fcontact-us-bg-2.webp&w=3840&q=75)
![Contact us bg 4](/_next/image?url=%2Fimages%2Fcontact-us-bg-4.webp&w=3840&q=75)
![Contact us bg 1](/_next/image?url=%2Fimages%2Fcontact-us-bg-1.webp&w=3840&q=75)
![Ball left](/_next/image?url=%2Fimages%2Fball-left.png&w=1080&q=75)
![Ball right](/_next/image?url=%2Fimages%2Fball-right.png&w=1920&q=75)
![Ball left](/_next/image?url=%2Fimages%2Fball-left.png&w=256&q=75)
![Ball right](/_next/image?url=%2Fimages%2Fball-right.png&w=384&q=75)
![Sennalabs gray logo](/_next/image?url=%2Fimages%2Fsennalabs-gray-logo.webp&w=256&q=75)