Conventional Commit message generator
สร้าง Conventional Commit message จาก staged diff อัตโนมัติ — ระบุ type, scope และ subject line ที่ชัดเจนตามมาตรฐาน พร้อมตัวอย่างหลากหลาย type, วิธีตั้งค่า git alias ทีละขั้นตอน และคำเตือนเกี่ยวกับการส่งข้อมูลลับ
ของ lazyyy เอง · อัปเดต 9 ส.ค. 2569
ส่วนประกอบ
Conventional Commit generator
Read the staged diff and write ONE Conventional Commit.
Format: <type>(<scope>): <subject>
- type: feat|fix|refactor|perf|docs|test|build|chore
- subject: imperative, <=72 chars, no trailing period
- Add a body ONLY if the change needs a "why". Wrap at 72 cols.
- Add "BREAKING CHANGE:" footer if a public contract changed.
Output the commit message and nothing else.
คำอธิบายเพิ่มเติม
staged diff คือความแตกต่างของไฟล์ที่คุณรัน git add แล้ว เตรียมพร้อมที่จะ commit — กล่าวคือ เป็นการเปรียบเทียบระหว่างไฟล์ในสถานะ staging area กับ commit ล่าสุด แสดงให้เห็นว่าคุณกำลังจะบันทึกการเปลี่ยนแปลงอะไรบ้าง
ตัวอย่าง commit message ที่สร้างได้
feat(auth): add OAuth2 login flow
Integrate third-party OAuth to reduce signup friction
fix(api): handle null response in user endpoint
refactor(parser): extract validation logic to separate module
perf(db): add index on user_id column
docs(readme): update installation steps for Node 18
Handy git alias
ตั้งค่า alias นี้เพื่อให้ Git ส่ง staged diff ไปยัง AI agent อัตโนมัติ:
# ขั้นตอนที่ 1: แทนที่ your-agent ด้วยคำสั่งเรียก AI ของคุณ
# เช่น claude, chatgpt-cli, lazyyy หรือ llm
git config --global alias.ai '!f(){ git diff --cached | your-agent > /tmp/msg && git commit -eF /tmp/msg; }; f'
your-agent คืออะไร?
your-agentคือคำสั่ง command-line ที่ใช้เรียก AI ของคุณ ซึ่งรับ input จาก stdin (pipe) และส่ง prompt พร้อม diff ไปยัง AI model- ตัวอย่างเครื่องมือที่ใช้ได้:
claude(Anthropic CLI),llm(Simon Willison's tool),chatgptหรือlazyyy - คุณต้องติดตั้งและตั้งค่า API key ของเครื่องมือนั้นๆ ก่อนใช้งาน
ตัวอย่างคำสั่งจริง:
# ตัวอย่างใช้ claude CLI
git config --global alias.ai '!f(){ git diff --cached | claude > /tmp/msg && git commit -eF /tmp/msg; }; f'
# ตัวอย่างใช้ llm
git config --global alias.ai '!f(){ git diff --cached | llm > /tmp/msg && git commit -eF /tmp/msg; }; f'
วิธีใช้งาน:
git addไฟล์ที่ต้องการ commit- รัน
git ai - AI จะอ่าน diff และสร้าง commit message
- Git จะเปิด editor ให้คุณตรวจสอบก่อน commit
⚠️ ข้อควรระวัง
- อย่าส่งข้อมูลลับ: ตรวจสอบให้แน่ใจว่า staged diff ไม่มี API keys, passwords, tokens หรือข้อมูลส่วนตัว
- ตรวจสอบก่อน commit: อ่าน commit message ที่ AI สร้างให้ใน editor เสมอ เพื่อความแม่นยำ
- โค้ดที่เป็นความลับของบริษัท: พิจารณาใช้ AI model ที่ self-hosted หรือไม่เก็บข้อมูล
หมายเหตุ: prompt นี้ทดสอบและทำงานได้ดีกับ GPT-4, Claude 3+ และ AI models ที่รองรับ context ยาว