---
title: "Memperbaiki kode"
version: 6.1
locale: id
source: https://docs.djangoproject.com/id/6.1/internals/contributing/committing-code/
canonical: https://djangodocs.dev/id/6.1/internals/contributing/committing-code/
---
# Memperbaiki kode

This section is addressed to the mergers and to anyone interested in knowing
how code gets committed into Django. The [Panduan perbaikan](#committing-guidelines) apply
to all contributors, with or without commit rights.

If you're a community member who wants to contribute code to Django, look at
[Bekerja dengan Git dan GitHub](/id/6.1/internals/contributing/writing-code/working-with-git/) instead.

## Penanganan pull request

Sejak Django disimpan pada GitHub, tambalan disediakan dalam formulir dari pull request.

When committing a pull request, make sure each individual commit matches the
commit guidelines described below. Contributors are expected to provide the
best pull requests possible. In practice mergers - who will likely be more
familiar with the commit guidelines - may decide to bring a commit up to
standard themselves.

You may want to have Jenkins or GitHub actions test the pull request with one
of the pull request builders that doesn't run automatically, such as Oracle or
Selenium. See the [CI wiki page](https://code.djangoproject.com/wiki/CI) for instructions.

If you find yourself checking out pull requests locally more often, this git
alias will be helpful:

```ini
[alias]
    pr = !sh -c \"git fetch upstream pull/${1}/head:pr/${1} && git checkout pr/${1}\"
```

Tambahkan ke `~/.gitconfig` anda, dan setel `upstream` menjadi `django/django`. Kemudian anda dapat menjalankan `git pr ####` untuk memeriksa pull request yang sama.

Pada titik ini, anda dapat bekerja pada kode. Gunakan `git rebase -i` dan `git commit --amend` untuk memastikan perbaikan mempunyai tingkatan yang diharapkan dari kualitas. Sekali anda sedang siap:

```console
$ # Pull in the latest changes from main.
$ git checkout main
$ git pull upstream main
$ # Rebase the pull request on main.
$ git checkout pr/####
$ git rebase main
$ git checkout main
$ # Merge the work as "fast-forward" to main to avoid a merge commit.
$ # (in practice, you can omit "--ff-only" since you just rebased)
$ git merge --ff-only pr/XXXX
$ # If you're not sure if you did things correctly, check that only the
$ # changes you expect will be pushed to upstream.
$ git push --dry-run upstream main
$ # Push!
$ git push upstream main
$ # Delete the pull request branch.
$ git branch -d pr/xxxx
```

*Windows*

```doscon
...\> REM Pull in the latest changes from main.
...\> git checkout main
...\> git pull upstream main
...\> REM Rebase the pull request on main.
...\> git checkout pr/####
...\> git rebase main
...\> git checkout main
...\> REM Merge the work as "fast-forward" to main to avoid a merge commit.
...\> REM (in practice, you can omit "--ff-only" since you just rebased)
...\> git merge --ff-only pr/XXXX
...\> REM If you're not sure if you did things correctly, check that only the
...\> REM changes you expect will be pushed to upstream.
...\> git push --dry-run upstream main
...\> REM Push!
...\> git push upstream main
...\> REM Delete the pull request branch.
...\> git branch -d pr/xxxx
```

Force push to the branch after rebasing on main but before merging and pushing
to upstream. This allows the commit hashes on main and the branch to match
which automatically closes the pull request.

Jika sebuah pull request tidak butuh digabungkan seperti banyak perbaikan, anda dapat menggunakan tombol "Squash and merge" GitHub. Sunting pesan perbaikan sesuai kebutuhan untuk menyesuaikan ke [the guidelines](#committing-guidelines) dan pindahkan angka pull request yang otomatis ditambahkan ke baris pertama pesan.

Ketika menulis kembali riwayat perbaikan dari pull request, tujuannya adalah membuat riwayat perbaikan django sebaik mungkin:

- Jika tambalan mengandung perbaikan bolak balik, lalu tulis kembali itu menjadi satu. Sebagai contoh, jika sebuah perbaikan menambahkan beberapa kode dan perbaikan kedua memperbaiki masalah gaya yang diperkenalkan di perbaikan pertama, perbaikan tersebut harus dilumat sebelum digabungkan.
- Perubahan terpisah pada perbaikan berbeda berdasarkan pengelompokan logika: jika anda melakukan pembersihan gaya pada saat bersamaan seperti anda melakukan perubahan lain pada berkas, memisahkan perubahan kedalam dua perbaikan berbeda akan membuat meninjauan riwayat lebih mudah.
- Waspada dari menggabungkan cabang upstream dalam pull request.
- Percobaan harus dilewati dan dokumen harus dibangun setelah setiap perbaikan. Juga tidak percobaan maupun dokumen harus mengeluarkan peringatan.
- Tambalan sepele dan kecil biasanya baik diselesaikan dalam satu perbaikan. Pekerjaan menengah sampai besar mungkin dipisah menjadi banyak perbaikan jika itu masuk akal.

Practicality beats purity, so it is up to each merger to decide how much
history mangling to do for a pull request. The main points are engaging the
community, getting work done, and having a usable commit history.

## Panduan perbaikan

These guidelines apply to all commits to Django's Git repository, whether
submitted by a contributor via a pull request or landed directly by a merger:

- Jangan pernah merubah riwayat telah diterbitkan dari cabang `django/django` dengan mendorong paksa. Jika anda mutlak harus (untuk alasan keamanan sebagai contoh), pertama obrolkan keadaan dengan tim.
- For any medium-to-big changes, where "medium-to-big" is according to
  your judgment, please bring things up on the [Django Forum](https://forum.djangoproject.com/) before making
  the change.

  If you bring something up and nobody responds, please don't take that
  to mean your idea is great and should be implemented immediately because
  nobody contested it. Everyone doesn't always have a lot of time to read
  discussions immediately, so you may have to wait a couple of days before
  getting a response.
- Write detailed commit messages in the past tense, not present tense, and
  end the subject line with a period.

  - Correct: "Fixed Unicode bug in RSS API."
  - Incorrect: "Fixes Unicode bug in RSS API." (present tense)
  - Incorrect: "Fixing Unicode bug in RSS API." ("-ing" form)
  - Incorrect: "Fixed Unicode bug in RSS API" (missing trailing period)

  The commit message should be in lines of 72 chars maximum. There should be
  a subject line, separated by a blank line and then paragraphs of 72 char
  lines. The limits are soft. For the subject line, shorter is better.

  In the body of the commit message more detail is better than less, and should
  explain *why* the change was made, not *what* was changed or *how*. The code
  itself shows what changed; the commit message should provide the context and
  reasoning that the code cannot.

  Credit the contributors in the commit message: "Thanks A for the report and B
  for review." Use git's [Co-Authored-By](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors) as appropriate, including anyone
  whose earlier work the change builds on.

  Sebagai contoh:

  ```
  Fixed #18307 -- Added git workflow guidelines.

  Refactored the Django's documentation to remove mentions of SVN
  specific tasks. Added guidelines of how to use Git, GitHub, and
  how to use pull request together with Trac instead.

  Thanks to Full Name for the report, and to Reviewer for reviews.
  ```
- Batasi perbaikan ke perubahan paling kecil sangat masuk akal. Ini berarti, gunakan sering perbaikan kecil daripada perbaikan besar yang jarang. Sebagai contoh, jika menerapkan fitur X membutuhkan perubahan kecil pada pustaka Y, pertama perbaiki perubahan pada pustaka Y, kemudian perbaiki fitur X di perbaikan berbeda. Ini berjalan *jauh* dalam membantu semua orang mengikuti perubahan anda.
- Separate bug fixes from feature changes. Bugfixes may need to be
  [backported](#backports).
- Jika perbaikan anda menutup sebuah tiket di [ticket tracker](https://code.djangoproject.com/) Django, mulai pesan perbaikan anda dengan teks "Fixed #xxxxx", dimana "xxxxx" adalah jumlah dari tiket perbaikan pembetulan. Contoh: "Fixed #123 -- Ditambahkan fitur ulung.". kami telah memperlengkapi Trac sehingga pesan perbaikan apapun di bentuk tersebut akan otomatis menutup acuan tiket dan penempatan komentar kepadanya dengan pesan perbaikan penuh.

  Untuk ingin tahu, kami menggunakan Tambahan Trac \_ untuk ini.

> **Note**
>
> Note that the Trac integration doesn't know anything about pull requests.
> So if you try to close a pull request with the phrase "closes #400" in your
> commit message, GitHub will close the pull request, but the Trac plugin
> will not close the same numbered ticket in Trac.

- Jika acuan perbaikan anda sebuah tiket di [ticket tracker](https://code.djangoproject.com/) Django tetapi *tidak* menutup tiket, termasuk frase "Refs #xxxxx", dimana "xxxxx" adalah nomor dari tiket acuan perbaikan anda. Ini akan otomatis menempatkan komentar pada tiket yang sesuai.

## Backports

Bug fix backports to stable branches are done exclusively by mergers, following
the [Versi didukung](/id/6.1/internals/release-process/#supported-versions-policy). A backport consists of cherry-picking a
commit from `main` onto the target `stable/A.B.x` branch.

A backport commit must include two things beyond the original commit message:

- A prefix `[A.B.x]` on the subject line, where `A.B.x` is the name of the
  `stable/A.B.x` branch being targeted.
- A suffix `Backport of <sha> from main.` line in the commit body, pointing
  to the original commit hash.

Sebagai contoh:

```
[1.3.x] Fixed #17028 -- Changed diveintopython.org -> diveintopython.net.

Backport of 80c0cbf1c97047daed2c5b41b296bbc56fe1d7e3 from main.
```

If the backport also fixes a regression, add a line identifying the commit that
introduced it:

```
Regression in 6ecccad711b52f9273b1acb07a57d3f806e93928.
```

There are three ways to do a backport, depending on your workflow:

**Option 1: fully manual**

Cherry-pick the commit onto the stable branch, then amend the commit message to
add the required prefix and backport note:

```shell
git cherry-pick <sha>
git commit --amend
```

If the cherry-pick produces conflicts, resolve them, stage the changes, then
run `git cherry-pick --continue` before amending. This option requires no
setup but relies entirely on remembering to format the message correctly.

**Option 2: using the helper script in the repo**

The `scripts/backport.sh` Bash script automates the cherry-pick and rewrites
the commit message with the correct prefix and backport note. Run it from the
target stable branch:

```shell
bash scripts/backport.sh <sha>
```

This is straightforward for clean cherry-picks, but if conflicts are produced,
you will need to resolve them manually and add the prefix and backport note to
the commit message yourself.

**Option 3: using the** `prepare-commit-msg` **git hook**

The `scripts/prepare_commit_msg.py` Python script can be installed as a
`prepare-commit-msg` git hook. It automatically adds the `[A.B.x]` prefix
to the subject line, appends `Backport of <sha> from main.` to the commit
body, and ensures the subject line ends with a period, even when the
cherry-pick produces conflicts. To install it, create an executable file
`.git/hooks/prepare-commit-msg` containing:

```sh
#!/bin/sh
exec python scripts/prepare_commit_msg.py "$@"
```

Once installed, a plain `git cherry-pick <sha>` on a stable branch is
sufficient; the hook handles the message formatting in all cases.

## Mengembalikan perbaikan

Tidak seorangpun sempurna; kesalahan akan diperbaiki.

But try very hard to ensure that mistakes don't happen. Just because we have a
reversion policy doesn't relax your responsibility to aim for the highest
quality possible. Really: double-check your work, or have it checked by
another merger **before** you commit it in the first place!

Ketika kesalahan perbaikan ditemukan, silahkan ikuti panduan ini:

- Jika memungkinkan, penulis asli mengembalikan perbaikan mereka sendiri.
- Jangan mengembalikan perubahan penulis lain tanpa perizinan dari penulis asli.
- Gunakan git revert -- ini akan membuat membalikkan perbaikan, tetapi perbaikan asli akan masih menjadi bagian dari riwayat perbaikan.
- If the original author can't be reached (within a reasonable amount
  of time -- a day or so) and the problem is severe -- crashing bug,
  major test failures, etc. -- then ask for objections on the [Django Forum](https://forum.djangoproject.com/)
  then revert if there are none.
- Jika masalah adalah kecil (perbaikan fitur setelah pembekuan fitur, katakan), tunggu saja.
- If there's a disagreement between the merger and the reverter-to-be then try
  to work it out on the [Django Forum](https://forum.djangoproject.com/) . If an agreement can't be reached then
  it should be put to a vote.
- Jika perbaikan diperkenalkan ditegaskan,  ungkap kerentanan keamanan kemudian perbaikan mungkin dirubah sesegera mungkin tanpa perizinan dari siapapun.
- Perawat cabang terbitan mungkin mengeluarkan perbaikan ke cabang terbitan tanpa perizinan jika perbaikan merusak cabang terbitan.
- Jika anda salah mendorong sebuah cabang topik ke `django/django`, hapus itu. Sebagai contoh, jika anda melakukan `git push upstream feature_antigravity`, lakukan dorongan balikan: `git push upstream :feature_antigravity`.
