{"title":"コードのコミット","version":"5.2","locale":"ja","docname":"internals/contributing/committing-code","url":"/ja/5.2/internals/contributing/committing-code/","canonical":"https://djangodocs.dev/ja/5.2/internals/contributing/committing-code/","summary":"このセクションは、マージする人や、コードがどのように Django にコミットされるのかに興味のある人向けのものです。","html":"<h1>コードのコミット<a class=\"heading-anchor\" href=\"#committing-code\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>このセクションは、マージする人や、コードがどのように Django にコミットされるのかに興味のある人向けのものです。もしあなたが Django にコードを貢献したいコミュニティメンバーなら、代わりに <a class=\"reference internal\" href=\"/ja/5.2/internals/contributing/writing-code/working-with-git/\"><span class=\"doc\">Working with Git and GitHub</span></a> を見てください。</p>\n<section id=\"handling-pull-requests\">\n<span id=\"id1\"></span><h2>プルリクエストの取り扱い<a class=\"heading-anchor\" href=\"#handling-pull-requests\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django は GitHub でホストされているので、パッチはプルリクエストの形で提供されます。</p>\n<p>プルリクエストをコミットする際には、個々のコミットが以下に説明するコミットガイドラインに合致していることを確認してください。コントリビューターは可能な限り最高のプルリクエストを提供することが期待されています。実際には、コミットガイドラインに精通しているであろうマージャーが、自分自身でコミットを標準に近づけることを決定するかもしれません。</p>\n<p>JenkinsやGitHubのアクションに、OracleやSeleniumのような自動で実行されないプルリクエストビルダーを使ってプルリクエストをテストさせたいかもしれません。手順については <a class=\"reference external\" href=\"https://code.djangoproject.com/wiki/CI\">CI wiki page</a> を参照してください。</p>\n<p>ローカルでプルリクエストをチェックすることが多くなったら、この git エイリアスが役立つでしょう:</p>\n<div class=\"code-block\" data-language=\"ini\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Ini</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Ini code\"><code><span class=\"k\">[alias]</span>\n    <span class=\"na\">pr</span> <span class=\"o\">=</span> <span class=\"s\">!sh -c \\&quot;git fetch upstream pull/${1}/head:pr/${1} &amp;&amp; git checkout pr/${1}\\&quot;</span>\n</code></pre></div>\n<p>これを <code class=\"docutils literal notranslate\">~/.gitconfig</code> に追加し、 <code class=\"docutils literal notranslate\">upstream</code> を <code class=\"docutils literal notranslate\">django/django</code> に設定してください。そして、 <code class=\"docutils literal notranslate\">git pr ####</code> を実行すると、対応するプルリクエストをチェックアウトできます。</p>\n<p>この時点で、コードに手を加えることができます。 <code class=\"docutils literal notranslate\">git rebase -i</code> と <code class=\"docutils literal notranslate\">git commit --amend</code> を使って、コミットの品質が期待通りのものであることを確認しましょう。準備ができたら次のようにします:</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-0-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span><span class=\"c1\"># Pull in the latest changes from main.</span>\n<span class=\"gp\">$ </span>git checkout main\n<span class=\"gp\">$ </span>git pull upstream main\n<span class=\"gp\">$ </span><span class=\"c1\"># Rebase the pull request on main.</span>\n<span class=\"gp\">$ </span>git checkout pr/####\n<span class=\"gp\">$ </span>git rebase main\n<span class=\"gp\">$ </span>git checkout main\n<span class=\"gp\">$ </span><span class=\"c1\"># Merge the work as &quot;fast-forward&quot; to main to avoid a merge commit.</span>\n<span class=\"gp\">$ </span><span class=\"c1\"># (in practice, you can omit &quot;--ff-only&quot; since you just rebased)</span>\n<span class=\"gp\">$ </span>git merge --ff-only pr/XXXX\n<span class=\"gp\">$ </span><span class=\"c1\"># If you&#39;re not sure if you did things correctly, check that only the</span>\n<span class=\"gp\">$ </span><span class=\"c1\"># changes you expect will be pushed to upstream.</span>\n<span class=\"gp\">$ </span>git push --dry-run upstream main\n<span class=\"gp\">$ </span><span class=\"c1\"># Push!</span>\n<span class=\"gp\">$ </span>git push upstream main\n<span class=\"gp\">$ </span><span class=\"c1\"># Delete the pull request branch.</span>\n<span class=\"gp\">$ </span>git branch -d pr/xxxx\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-0-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Pull in the latest changes from main.</span>\n<span class=\"gp\">...\\&gt;</span> git checkout main\n<span class=\"gp\">...\\&gt;</span> git pull upstream main\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Rebase the pull request on main.</span>\n<span class=\"gp\">...\\&gt;</span> git checkout pr/####\n<span class=\"gp\">...\\&gt;</span> git rebase main\n<span class=\"gp\">...\\&gt;</span> git checkout main\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Merge the work as &quot;fast-forward&quot; to main to avoid a merge commit.</span>\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM (in practice, you can omit &quot;--ff-only&quot; since you just rebased)</span>\n<span class=\"gp\">...\\&gt;</span> git merge --ff-only pr/XXXX\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM If you&#39;re not sure if you did things correctly, check that only the</span>\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM changes you expect will be pushed to upstream.</span>\n<span class=\"gp\">...\\&gt;</span> git push --dry-run upstream main\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Push!</span>\n<span class=\"gp\">...\\&gt;</span> git push upstream main\n<span class=\"gp\">...\\&gt;</span> <span class=\"c1\">REM Delete the pull request branch.</span>\n<span class=\"gp\">...\\&gt;</span> git branch -d pr/xxxx\n</code></pre></div></div></div>\n<p>ブランチを強制的にプッシュします。これにより、メインとブランチのコミットハッシュが一致するようになり、プルリクエストが自動的にクローズされます。</p>\n<p>プルリクエストを複数のコミットとしてマージする必要がない場合は、GitHub の &quot;Squash and merge&quot; ボタンを使ってください。コミットメッセージを <a class=\"reference internal\" href=\"#committing-guidelines\"><span class=\"std std-ref\">ガイドライン</span></a> に合うように必要に応じて編集し、メッセージの最初の行に自動的に付加されるプルリクエスト番号を削除します。</p>\n<p>プルリクエストのコミット履歴を書き換えるとき、その目的は Django のコミット履歴をできるだけ有用なものにすることです:</p>\n<ul class=\"simple\">\n<li><p>パッチに前後のコミットが含まれている場合は、それらをひとつに書き換えてください。たとえば、あるコミットでコードが追加され、2番目のコミットで最初のコミットで発生した文体上の問題が修正された場合、マージする前にそれらのコミットをひとつにまとめる必要があります。</p></li>\n<li><p>異なるコミットへの変更を論理的なグループ分けで分ける: ファイルへの他の変更と同時にスタイルのクリーンアップを行う場合、変更を 2 つの異なるコミットに分けることで、履歴のレビューがしやすくなります。</p></li>\n<li><p>プルリクエスト内の上流ブランチのマージに注意してください。</p></li>\n<li><p>コミットするたびに、テストをパスし、ドキュメントをビルドしなければなりません。テストもドキュメントも警告を出すべきではありません。</p></li>\n<li><p>些細なパッチや小さなパッチは通常1つのコミットで行うのがベストです。中規模から大規模の作業については、理にかなっていれば複数のコミットに分けても構いません。</p></li>\n</ul>\n<p>実用性は純粋さに勝るので、プルリクエストに対してどの程度履歴を加工するかは各マージャー次第です。主なポイントは、コミュニティを巻き込むこと、仕事を終わらせること、そして使えるコミット履歴を持つことです。</p>\n</section>\n<section id=\"committing-guidelines\">\n<span id=\"id2\"></span><h2>コミットガイドライン<a class=\"heading-anchor\" href=\"#committing-guidelines\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>また、Django の Git リポジトリにコードをコミットする際には、以下のガイドラインに従ってください:</p>\n<ul>\n<li><p>強制プッシュによって <code class=\"docutils literal notranslate\">django/django</code> ブランチの公開履歴を変更してはいけません。どうしても必要な場合 (例えばセキュリティ上の理由) は、まずチームと話し合ってください。</p></li>\n<li><p>For any medium-to-big changes, where &quot;medium-to-big&quot; is according to\nyour judgment, please bring things up on the <a class=\"reference external\" href=\"https://forum.djangoproject.com/\">Django Forum</a> before making\nthe change.</p>\n<p>If you bring something up and nobody responds, please don't take that\nto mean your idea is great and should be implemented immediately because\nnobody contested it. Everyone doesn't always have a lot of time to read\ndiscussions immediately, so you may have to wait a couple of days before\ngetting a response.</p>\n</li>\n<li><p>コミットメッセージは、現在形ではなく過去形で詳細を書いてください。</p>\n<ul class=\"simple\">\n<li><p>良い例: &quot;Fixed Unicode bug in RSS API.&quot;</p></li>\n<li><p>悪い例: &quot;Fixes Unicode bug in RSS API.&quot;</p></li>\n<li><p>悪い例: &quot;Fixing Unicode bug in RSS API.&quot;</p></li>\n</ul>\n<p>コミットメッセージは、最大72文字の行で記述するべきです。件名の行があり、空行で区切った後に72文字の行で段落を構成します。これらの制限は厳格ではありません。件名に関しては、短い方が良いです。コミットメッセージの本文では、詳細な情報が少ない情報よりも好ましいです:</p>\n<div class=\"code-block\" data-language=\"none\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">None</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"None code\"><code>Fixed #18307 -- Added git workflow guidelines.\n\nRefactored the Django&#39;s documentation to remove mentions of SVN\nspecific tasks. Added guidelines of how to use Git, GitHub, and\nhow to use pull request together with Trac instead.\n</code></pre></div>\n<p>&quot;Thanks A for the report and B for review.&quot; のように、コミットメッセージでコントリビューターをクレジットしてください。git の <a class=\"reference external\" href=\"https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors\">Co-Authored-By</a> を適切に使用してください。</p>\n</li>\n<li><p>ブランチへのコミットの場合は、コミットメッセージの前にブランチ名をつけます。たとえば &quot;[1.4.x] Fixed #xxxxx -- Added support for mind reading.&quot; のようにします。</p></li>\n<li><p>コミットは、意味のある最も細かい変更に限定しましょう。つまり、大きなコミットをたまに行うのではなく、小さなコミットをまめに行うようにしましょう。たとえば、機能Xの実装にライブラリYへの小さな変更が必要な場合、まずライブラリYへの変更をコミットし、その後、別のコミットで機能Xをコミットします。これは、皆があなたの変更に追いつくのに*大いに役立ちます*。</p></li>\n<li><p>機能変更からバグ修正を分けてください。バグ修正は <a class=\"reference internal\" href=\"/ja/5.2/internals/release-process/#supported-versions-policy\"><span class=\"std std-ref\">サポートバージョン</span></a> に基づいて安定ブランチにバックポートする必要があることがあるためです。</p></li>\n<li><p>あなたのコミットが Django <a class=\"reference external\" href=\"https://code.djangoproject.com/\">ticket tracker</a> のチケットをクローズする場合、コミットメッ セージを &quot;Fixed #xxxxx&quot; というテキストで始めます。例:  &quot;Fixed #123 -- Added whizbang feature.&quot;。 Trac では、この形式のコミットメッセージは自動的に参照されたチケットをクローズし、完全なコミットメッセージとともにコメントを投稿するように設定しています。</p>\n<p>好奇心旺盛な方のために、私たちはこのために <a class=\"reference external\" href=\"https://github.com/trac-hacks/trac-github\">Trac plugin</a> を使っています。</p>\n</li>\n</ul>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p>Trac との統合はプルリクエストについて何も知らないことに注意してください。そのため、コミットメッセージに &quot;closes #400&quot; と書いてプルリクエストをクローズしようとすると、GitHub はプルリクエストをクローズしますが、Trac プラグインは Trac で同じ番号のチケットをクローズしません。</p>\n</aside>\n<ul>\n<li><p>あなたのコミットが Django <a class=\"reference external\" href=\"https://code.djangoproject.com/\">ticket tracker</a> のチケットを参照しているものの、そのチケットを <em>クローズ</em> はしていない場合、&quot;Refs #xxxxx &quot;というフレーズを含めてください。&quot;xxxxx &quot;はあなたのコミットが参照しているチケットの番号です。これで自動的に適切なチケットにコメントが投稿されます。</p></li>\n<li><p>このパターンを使ってバックポートのコミットメッセージを書いてください:</p>\n<div class=\"code-block\" data-language=\"none\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">None</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"None code\"><code>[&lt;Django version&gt;] Fixed &lt;ticket&gt; -- &lt;description&gt;\n\nBackport of &lt;revision&gt; from &lt;branch&gt;.\n</code></pre></div>\n<p>例えば:</p>\n<div class=\"code-block\" data-language=\"none\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">None</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"None code\"><code>[1.3.x] Fixed #17028 -- Changed diveintopython.org -&gt; diveintopython.net.\n\nBackport of 80c0cbf1c97047daed2c5b41b296bbc56fe1d7e3 from main.\n</code></pre></div>\n<p>` これを自動化するスクリプト &lt;<a class=\"reference external\" href=\"https://code.djangoproject.com/wiki/MergerTips#AutomatingBackports\">https://code.djangoproject.com/wiki/MergerTips#AutomatingBackports</a>&gt;`_ が wiki にあります。</p>\n<p>コミットによってリグレッションが修正された場合は、その旨をコミットメッセージに含めてください:</p>\n<div class=\"code-block\" data-language=\"none\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">None</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"None code\"><code>Regression in 6ecccad711b52f9273b1acb07a57d3f806e93928.\n</code></pre></div>\n<p>(リグレッションが取り込まれたコミットハッシュを使用します)。</p>\n</li>\n</ul>\n</section>\n<section id=\"reverting-commits\">\n<h2>コミットの取り消し<a class=\"heading-anchor\" href=\"#reverting-commits\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>完璧な人はいません。間違ったコミットがなされることもあります。</p>\n<p>しかし、ミスが起こらないように最大限の努力をしましょう。私たちに差し戻しポリシーがあるからといって、可能な限り最高の品質を目指すあなたの責任が緩和されるわけではありません。本当に: 自分の仕事をダブルチェックするか、そもそもコミットする**前に**別のマージャーにチェックしてもらいましょう！</p>\n<p>誤ったコミットが発見された場合は、以下のガイドラインに従ってください:</p>\n<ul class=\"simple\">\n<li><p>可能であれば、元の作者に自分のコミットを差し戻してもらいましょう。</p></li>\n<li><p>原作者の許可なく、他の作者の変更を元に戻さないでください。</p></li>\n<li><p>git revert を使用します。これは逆コミットを行いますが、元のコミットはコミット履歴に残ります。</p></li>\n<li><p>If the original author can't be reached (within a reasonable amount\nof time -- a day or so) and the problem is severe -- crashing bug,\nmajor test failures, etc. -- then ask for objections on the <a class=\"reference external\" href=\"https://forum.djangoproject.com/\">Django Forum</a>\nthen revert if there are none.</p></li>\n<li><p>問題が小さい場合（例えば、機能フリーズ後の機能コミット）は、そのまま待ちましょう。</p></li>\n<li><p>If there's a disagreement between the merger and the reverter-to-be then try\nto work it out on the <a class=\"reference external\" href=\"https://forum.djangoproject.com/\">Django Forum</a> . If an agreement can't be reached then\nit should be put to a vote.</p></li>\n<li><p>もしそのコミットが、確認され、公開されたセキュリティ脆弱性を含んでいた場合、そのコミットは誰の許可も得ずに即座に差し戻されるかもしれません。</p></li>\n<li><p>リリースブランチのメンテナは、そのコミットがリリースブランチを壊してしまった場合、許可なくリリースブランチへのコミットを取り消すことができます。</p></li>\n<li><p>誤ってトピックブランチを <code class=\"docutils literal notranslate\">django/django</code> にプッシュした場合は、削除してください。例えば、 <code class=\"docutils literal notranslate\">git push upstream feature_antigravity</code> を実行した場合は、逆のプッシュを行ってください: <code class=\"docutils literal notranslate\">git push upstream :feature_antigravity</code> 。</p></li>\n</ul>\n</section>","rootId":"committing-code","toc":[{"title":"プルリクエストの取り扱い","anchor":"handling-pull-requests","children":[]},{"title":"コミットガイドライン","anchor":"committing-guidelines","children":[]},{"title":"コミットの取り消し","anchor":"reverting-commits","children":[]}],"breadcrumbs":[{"docname":"internals/index","title":"Django internals","url":"/ja/5.2/internals/"},{"docname":"internals/contributing/index","title":"Django へのコントリビュート","url":"/ja/5.2/internals/contributing/"},{"docname":"internals/contributing/writing-code/index","title":"Contributing code","url":"/ja/5.2/internals/contributing/writing-code/"}],"prev":{"docname":"internals/contributing/accessibility","title":"アクセシビリティ","url":"/ja/5.2/internals/contributing/accessibility/"},"next":{"docname":"internals/contributing/writing-documentation","title":"ドキュメントを書く","url":"/ja/5.2/internals/contributing/writing-documentation/"},"formats":{"html":"/ja/5.2/internals/contributing/committing-code/","markdown":"/ja/5.2/internals/contributing/committing-code.md","json":"/ja/5.2/internals/contributing/committing-code.json"},"source":"https://github.com/django/django/blob/stable/5.2.x/docs/internals/contributing/committing-code.txt","official":"https://docs.djangoproject.com/ja/5.2/internals/contributing/committing-code/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}