tutorial, git,

Conventional Commits: Standar Pesan Commit untuk Tim yang Profesional

Kiki/🎮🍉⌨️🍩💻 Kiki/🎮🍉⌨️🍩💻 Sep 24, 2026 · 6 mins read
Conventional Commits: Standar Pesan Commit untuk Tim yang Profesional
Share this

Histori Git yang baik adalah aset tim yang sangat berharga. Ketika membaca git log, kamu harus bisa langsung memahami apa yang terjadi di setiap commit tanpa harus buka kode. Conventional Commits adalah spesifikasi yang memberikan aturan yang ringan tapi konsisten untuk penulisan pesan commit — dan jika dikombinasikan dengan tool yang tepat, bisa otomatis menghasilkan changelog dan menentukan versi rilis.


Format Conventional Commits

<type>(<scope>): <deskripsi singkat>
<baris kosong>
[body opsional]
<baris kosong>
[footer opsional]

Contoh Lengkap

feat(auth): tambah login dengan Google OAuth

Mengintegrasikan Google OAuth 2.0 sebagai alternatif login.
User bisa klik "Login dengan Google" di halaman login.

Membutuhkan env variable GOOGLE_CLIENT_ID dan GOOGLE_CLIENT_SECRET.

Closes #45
BREAKING CHANGE: endpoint /auth/login sekarang menerima provider optional field

Tipe Commit

Type Kapan Digunakan Versi SemVer
feat Fitur baru MINOR naik
fix Perbaikan bug PATCH naik
docs Perubahan dokumentasi saja —
style Formatting, whitespace (bukan logika) —
refactor Refactoring tanpa fitur baru/bugfix —
perf Peningkatan performa PATCH naik
test Menambah/memperbaiki test —
build Sistem build, dependency —
ci Konfigurasi CI/CD —
chore Pemeliharaan umum —
revert Revert commit sebelumnya —

Breaking Change → MAJOR Naik

Breaking change ditandai dengan ! setelah type atau footer BREAKING CHANGE::

# Dengan tanda seru
feat(api)!: ubah format response semua endpoint

# Atau di footer
feat(api): ubah format response semua endpoint

BREAKING CHANGE: field 'data' sekarang selalu berupa array,
bukan object tunggal. Klien harus update cara parsing response.

Scope

Scope (opsional) menentukan bagian kode mana yang terpengaruh:

feat(auth): ...        # modul autentikasi
fix(ui/button): ...    # komponen button di UI
docs(api): ...         # dokumentasi API
refactor(database): ...
chore(deps): update express ke v4.18.2

Aturan Deskripsi

  • Huruf kecil semua (bukan “Tambah Fitur”, tapi “tambah fitur”)
  • Tanpa titik di akhir
  • Imperatif — “tambah” bukan “menambahkan” atau “ditambahkan”
  • Maksimal 50-72 karakter
  • Bahasa konsisten — pilih Indonesia atau Inggris, jangan campur

Otomasi dengan Commitizen

Commitizen adalah tool CLI yang membantu menulis commit message yang valid dengan prompt interaktif.

# Install global
npm install -g commitizen cz-conventional-changelog

# Setup di project
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc

# Gunakan sebagai pengganti git commit
git cz
# atau
cz commit

Commitizen akan menampilkan prompt:

? Select the type of change: (Use arrow keys)
❯ feat:     A new feature
  fix:      A bug fix
  docs:     Documentation only changes
  style:    Changes that do not affect the meaning of the code
  ...

? What is the scope of this change? (press enter to skip): auth

? Write a short, imperative description:  tambah login Google OAuth

? Provide a longer description? (press enter to skip):
  Mengintegrasikan Google OAuth 2.0...

? Are there any breaking changes? No

? Does this change close any open issues? Yes
? Add issue references: Closes #45

Validasi dengan commitlint

commitlint memvalidasi pesan commit secara otomatis saat developer mencoba commit.

npm install --save-dev @commitlint/cli @commitlint/config-conventional

commitlint.config.js:

module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [2, 'always', [
      'feat', 'fix', 'docs', 'style', 'refactor',
      'perf', 'test', 'build', 'ci', 'chore', 'revert'
    ]],
    'subject-case': [2, 'always', 'lower-case'],
    'subject-max-length': [2, 'always', 72],
    'body-max-line-length': [2, 'always', 100],
  }
};

Hubungkan dengan Git hooks via Husky:

npm install --save-dev husky
npx husky init

# Tambahkan hook commit-msg
echo "npx --no -- commitlint --edit \$1" > .husky/commit-msg
chmod +x .husky/commit-msg

Sekarang setiap commit yang tidak sesuai format akan ditolak otomatis:

git commit -m "tambah fitur"
# ⧗   input: tambah fitur
# ✖   subject may not be empty [subject-empty]
# ✖   type may not be empty [type-empty]
# ✖   found 2 problems, 0 warnings

Generate Changelog Otomatis dengan standard-version

npm install --save-dev standard-version

package.json:

{
  "scripts": {
    "release": "standard-version",
    "release:minor": "standard-version --release-as minor",
    "release:major": "standard-version --release-as major"
  }
}
# Buat release otomatis
npm run release

standard-version akan:

  1. Menentukan versi berikutnya berdasarkan commit (feat → minor, fix → patch)
  2. Update package.json dengan versi baru
  3. Generate/update CHANGELOG.md dari commit messages
  4. Buat commit release
  5. Buat tag versi

Contoh CHANGELOG yang Dihasilkan

# Changelog

## [1.3.0] - 2026-09-24

### Features
- **auth:** tambah login dengan Google OAuth (#45)
- **ui:** tambah dark mode dengan sistem preference (#38)

### Bug Fixes
- **api:** perbaiki error 500 pada endpoint /users (#52)
- **auth:** perbaiki token refresh yang expired terlalu cepat (#49)

### Performance Improvements
- **database:** optimasi query pencarian dengan index (#44)

Tips Menulis Commit yang Baik

# Kurang baik — tidak informatif
git commit -m "fix bug"
git commit -m "update kode"
git commit -m "perubahan"
git commit -m "wip"

# Baik — informatif dan konsisten
git commit -m "fix(auth): perbaiki validasi token yang gagal saat timezone berbeda"
git commit -m "feat(search): tambah filter berdasarkan kategori dan tanggal"
git commit -m "perf(db): tambah index pada kolom email di tabel users"
git commit -m "docs(api): tambah contoh request/response di swagger"

Kesimpulan

Conventional Commits bukan tentang birokrasi — ini tentang membangun histori kode yang bisa dibaca oleh semua anggota tim, bahkan 2 tahun ke depan. Dengan commitlint dan Husky, standar ini ditegakkan secara otomatis tanpa bergantung pada disiplin manual.

Di artikel berikutnya, kita bahas Git Hooks — cara menjalankan script otomatis pada event-event Git tertentu untuk otomasi di level repository.

Kiki/🎮🍉⌨️🍩💻
Written by Kiki/🎮🍉⌨️🍩💻
hello I'm friend K.