2014-05-09 16:48:06 +0000 2014-05-09 16:48:06 +0000
135
135
Advertisement

GitHub でコミットメッセージを編集する方法はありますか?

Advertisement

コミットして GitHub にプッシュした後にコミットメッセージを編集する方法はありますか?インラインコメントの他に ‘add a note’ という機能があるようですが、実際にコミットメッセージを編集する方法はありません。git extensions には ‘amend commit’ というものがありますが、これは既存のメッセージを編集するものではありません。

Advertisement

Respuestas (5)

189
189
189
2014-05-10 10:27:44 +0000
  1. git rebase -i <commit hash you want to change>^

  2. メッセージを変更したいコミットについては、pickrewordに変更してください。

  3. 保存して終了(viでは:wq)。

  4. このようなコミットごとに、コミットメッセージを編集するためのエディタが表示されます。適当に変更して、保存して終了します。

  5. これで、git push origin --forceを使ってgithubにアップロードできるようになりました。

最後のコミットを修正するだけなら、ステップ1~4をgit commit --amendに置き換えることができます。

35
35
35
2018-06-18 09:49:45 +0000

Intellij Ideaでは、とても簡単にできます。

1.バージョン管理(履歴)を開く 2. ログタブを選択 3. コメントを変更するコミットを選択 4. F2 (Mac fn + F2)を押して、コミットメッセージを更新する。

3
Advertisement
3
3
2019-03-14 07:29:36 +0000

前提:

git-graph が以下のようになっていれば…

O target-commit that you want to change its message [df9c192]
|
O parent-commit [b7ec061]
|
O

(df9c192b7ec061 はそれぞれ target-commit と parent-commit のコミットハッシュです)

解決方法。

以下の命令を入力するだけでOKです。

git reset --soft b7ec061
git commit -m "your_new_description"
git push -f

解説。

  1. git reset --soft b7ec061 はファイルの変更を保持し、親コミットにリセットします(例: b7ec061)
  2. git commit -m "..." はローカルに新しいコミットを作成する
  3. git push -f は新しいコミットをサーバにプッシュし、古いコミットを置き換えます (例: df9c192)
2
2
2
2018-08-08 22:27:59 +0000

もうひとつの方法は、エラーを含むコミットオブジェクトを参照する “errata コミット” を追加して (そしてプッシュして) 作成することです。errata コミットとは、実質的なコードの変更はないものの、重要なコミットメッセージを含むコミットのことです。これはリベースよりも簡単で安全ですし、真の履歴を変更することもありませんし、ブランチツリーをきれいに保つことができます (最新のコミットを修正する場合は --allow-empty を使うのもいいでしょうが、古いコミットの場合はエラッタコミットを使うのもいいでしょう)。このようなことは滅多に起こらないので、間違いを文書化するだけで十分です。将来的には、git のログから機能キーワードを探す必要が出てきたときに、元の (誤った) コミットが表示されなくなるかもしれません。以下に例を示します:

$ git log commit 0c28141c68adae276840f17ccd4766542c33cf1d Author: First Last Date: Wed Aug 8 15:55:52 2018 -0600 Errata commit: This commit has no substantive code change. THis commit is provided only to document a correction to a previous commit message. This pertains to commit object e083a7abd8deb5776cb304fa13731a4182a24be1 Original incorrect commit message: Changed background color to red Correction (\*change highlighted\*): Changed background color to \*blue\* commit 032d0ff0601bff79bdef3c6f0a02ebfa061c4ad4 Author: First Last Date: Wed Aug 8 15:43:16 2018 -0600 Some interim commit message commit e083a7abd8deb5776cb304fa13731a4182a24be1 Author: First Last Date: Wed Aug 8 13:31:32 2018 -0600 Changed background color to red
0
Advertisement
0
0
2019-08-24 11:01:51 +0000

@Mureinikさんの回答は良いが、初心者には理解できない。

最初の方法:

  1. 最新のコミットメッセージを編集したいだけなら、git commit --amendだけで済む。
<your existing commit mesage foo bar> 

# Please enter the commit message fir your changes. Lines starting
# with # will be ignored, and an empty message aborts the commit.
#
# Date: Sat Aug 24 17:56:16 2019 +0800
#
# On branch is up to date with 'origin/master'.
#
# changes to be committed:
# modified: foo.py
#
  1. ご覧のように、pickのようなコマンドの接頭辞を付けずに先頭にあるコミットメッセージは、すでに**編集ページになっており、先頭のメッセージの編集保存と終了*を指示することができます。
<your new correction commit message> 

# Please enter the commit message for your changes. Lines starting
....
  1. その後、git push -u origin master --force または <how you push normally> --force を実行します。ここで重要なのは --force です。

2番目の方法:

  1. コミットハッシュはgit logで確認するか、リポジトリのURLから抽出します(私の場合は881129d771219cfa29e6f6c2205851a2994a8835

  2. 次に、git rebase --interactive 881129d771219cfa29e6f6c2205851a2994a8835 または git rebase -i HEAD^ (最新の場合)

  3. このようになります。

pick <commit hash> <your current commit message>

# Rebase 8db7e8b..fa20af3 onto 8db7e8b
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
  1. しかし、noopが表示される場合は、おそらく間違った入力をしている可能性があります。例えば、git rebase -i 881129d771219cfa29e6f6c2205851a2994a88を実行しても最後に^が表示されない場合は、保存せずにエディタを終了して、その理由を考えた方が良いでしょう。 Save&quitすると、メソッド#1と同じような 編集ページ が表示されます:
noop

# Rebase 8db7e8b..fa20af3 onto 8db7e8b
...
  1. 上部のメッセージを編集し、メソッド#1と同じように save&quitします、例:
reword <commit hash> <your current commit message>

# Rebase 8db7e8b..fa20af3 onto 8db7e8b
#
# Commands:
# p, pick = use commit
...
  1. ここでもメソッド#1と同じように、noop または pick を実行します。ここで重要なのは reword です。

詳細は doc を読んでください。

Advertisement