我想要更改【Git】的提交消息(使用git rebase -i)

这种情况下

哎呀〜我好想修改提交消息呢〜。

– 总纲
– 手段
– 步骤
– 程序
– 技巧
– 方式
– 途径
– 措施
– 途径
– 行动

git日志:我想要更改n个之前的提交信息!

git rebase -i HEAD~n

自动打开vim。将要更改的提交的开头的pick改为edit。

git commit –amend -m “<新的提交信息>”

git rebase –continue

git日志:已成功进行更改!

说明

查看 git log:查看提交消息

% git log --oneline
e35aade (HEAD -> master) commit 4
754cc2f commit 2 # ここのメッセージを変えたい!
25c09e4 commit 2
58e25f0 commit 1

改变第二个消息从头部。

git rebase -i HEAD~n:编辑前n个提交

% git rebase -i HEAD~2

根据第二个提交,可以用HEAD~2表示。
然后,Vim会自动启动。

启动vim

    pick
     ↓
  1 edit 754cc2f commit 2
  2 pick e35aade commit 4
  3
  4 # Rebase 25c09e4..e35aade onto 25c09e4 (2 commands)
  5 #
  6 # Commands:
  7 # p, pick <commit> = use commit
  8 # r, reword <commit> = use commit, but edit the commit message
  9 # e, edit <commit> = use commit, but stop for amending
 10 # s, squash <commit> = use commit, but meld into previous commit
 11 # f, fixup <commit> = like "squash", but discard this commit's log message
 12 # x, exec <command> = run command (the rest of the line) using shell
 13 # b, break = stop here (continue rebase later with 'git rebase --continue')
 14 # d, drop <commit> = remove commit
 15 # l, label <label> = label current HEAD with a name
 16 # t, reset <label> = reset HEAD to a label
 17 # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
 18 # .       create a merge commit using the original merge commit's
 19 # .       message (or the oneline, if no original merge commit was
 20 # .       specified). Use -c <commit> to reword the commit message.
 21 #
 22 # These lines can be re-ordered; they are executed from top to bottom.
 23 #
 24 # If you remove a line here THAT COMMIT WILL BE LOST.
 25 #
 26 # However, if you remove everything, the rebase will be aborted.
 27 #
 28 # Note that empty commits are commented out

将第一行的”pick”更改为”edit”,然后结束。回到zsh以后,

Stopped at 754cc2f...  commit 2
You can amend the commit now, with

  git commit --amend

Once you are satisfied with your changes, run

  git rebase --continue

正在出现。

修改提交消息:git commit –amend -m “<新的提交消息>”

% git commit --amend -m "commit 3"
[detached HEAD eaf967d] commit 3
 Date: Xxx Xxx 00 00:00:00 0000 +0000
 1 file changed, 2 deletions(-)
 delete mode 100644 test2.html

在这里,输入想要修改的消息。

git rebase –continue:结束 rebase 操作

% git rebase --continue
Successfully rebased and updated refs/heads/master.

git log: 查看提交消息

% git  log --oneline
0b421f9 (HEAD -> master) commit 4
eaf967d commit 3 # 変わっている
25c09e4 commit 2
58e25f0 commit 1

一切都已经改变。

研究者的廢話

关于 git rebase

正在进行更新…

广告
将在 10 秒后关闭
bannerAds