假设我跑了 git rebase -i HEAD~3
pick 6b24464 foo
pick a681432 Foo
pick 8ccba08 foo foo
# Rebase 960c384..8ccba08 onto 960c384
#
# 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
Run Code Online (Sandbox Code Playgroud)
我想直接从这个文件重新提交消息,而不是一次编辑一个提交消息(按照惯例reword),如下所示:
reword 6b24464 foo bar
reword a681432 Foo Bar
reword 8ccba08 foo foo bar bar
# Rebase 960c384..8ccba08 onto 960c384
#
# 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
Run Code Online (Sandbox Code Playgroud)
我曾希望这可以使用reword或者完成edit,但我似乎无法弄清楚如何(如果可能的话).我已经能够实现相同的结果
x git cherry-pick 6b24464 && git commit -amend "foo bar"
Run Code Online (Sandbox Code Playgroud)
然而,这比我想要的大型rebase更耗时.有任何想法吗?
And*_*w C 21
您可以使用该exec选项来实现您想要的效果.
使用类似于的exec命令 git commit --amend -m "this is the new message"
你可以直接使用它,或者如果你需要更复杂,可以把它放在一个叫做的外部脚本中my_reword.
#!/bin/sh
git commit --amend -m "$1"
Run Code Online (Sandbox Code Playgroud)
然后在exec任何地方添加行
pick 6b24464 foo
pick a681432 Foo
x my_reword "this is a new message"
pick 8ccba08 foo foo
Run Code Online (Sandbox Code Playgroud)
我不相信可以做到,因为当你这样做时,你git rebase -i只得到每个提交消息的第一行,而不是完整的提交消息.
作为约定,提交消息应该使第一行只是摘要,并且在以下行中有关于更改的更多详细信息.这是关于如何编写正确的提交消息的Linus Torvalds
因此,即使您每次提交可能只执行了一行消息,这也不是git所假设的,因此它不会让您通过"每个提交视图一行"编辑提交消息.
添加到我的.gitconfig:
[alias]
w = "!reword() { git commit --amend -m \"$1\"; }; reword"
Run Code Online (Sandbox Code Playgroud)
然后,x git w "..."就像Andrew C在他的回答中提出的那样。
据我所知,人们通常也命名别名ca......