使用git rebase,有没有办法使用默认命令在git-rebase-todo中重写提交消息?

时间:2015-03-22 18:39:46

标签: git git-rebase

假设我运行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

我想直接从此文件重新提交消息,而不是一次编辑一个提交消息(按照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

我曾希望只使用rewordedit来完成此操作,但我似乎无法弄清楚如何(如果可能的话)。我已经能够用

获得相同的结果
x git cherry-pick 6b24464 && git commit -amend "foo bar"

然而,这比我想要的大型基数更耗时。有什么想法吗?

5 个答案:

答案 0 :(得分:18)

您可以使用exec选项来实现您的目标。

使用类似于git commit --amend -m "this is the new message"

的exec命令

您可以直接使用它,或者如果您需要更复杂,可以将其放在名为my_reword的外部脚本中。

#!/bin/sh
git commit --amend -m "$1"

然后在exec行添加您想要的地方

pick 6b24464 foo
pick a681432 Foo
x my_reword "this is a new message"
pick 8ccba08 foo foo

答案 1 :(得分:9)

我不相信可以这样做,因为当你执行git rebase -i时,你只得到每个提交消息的第一行,而不是完整的提交消息。

作为约定,提交消息应该使第一行只是摘要,并在以下行中提供有关更改的更多详细信息。 Here's Linus Torvalds on how to write a proper commit message

  

另外,请写好git提交消息。一个好的提交消息如下所示:

Header line: explain the commit in one line (use the imperative)

Body of commit message is a few lines of text, explaining things
in more detail, possibly giving some background about the issue
being fixed, etc etc.

The body of the commit message can be several paragraphs, and
please do proper word-wrap and keep columns shorter than about
74 characters or so. That way "git log" will show things
nicely even when it's indented.

Make sure you explain your solution and why you're doing what you're
doing, as opposed to describing what you're doing. Reviewers and your
future self can read the patch, but might not understand why a
particular solution was implemented.

Reported-by: whoever-reported-it
Signed-off-by: Your Name <youremail@yourhost.com>
     

那个标题行确实应该有意义,而且实际上应该只是一行。该标题行是gitk和shortlog等工具所显示的内容,应该在一个可读文本行中汇总更改,与更长的解释无关。请在提交消息中使用命令中的动词,如Fix bug that...Add file/feature ...Make Subsurface...

所以,即使你可能每次提交只做了一行消息,这不是git所假设的,所以它不会让你通过&#34;每次提交一行来编辑提交消息视图&#34;

答案 2 :(得分:0)

不,您无法在rebase TODO文件中重新加载邮件。

原因是:Git从上到下应用了rebase。 TODO文件只告诉Git执行rebase操作的顺序,以及它的操作(壁球,重写,使用,修复等)。然后它依赖其他机制(如commit)来处理其余的事情。

如果你有很多改写提交,你会收到很多提示来编辑消息,就是你应该期待的;您正在使用新邮件创建新提交[无论如何],因此Git应该要求您在处理rebase操作时将其输入。

我强烈反对大规模的反叛行动,因为它会导致这种平凡的事情,并且它有可能比它的价值更危险。

答案 3 :(得分:0)

已添加到我的# If V1_emb and V2_emb have different shapes you need to take the shape of each one s = tf.shape(V1, out_type=V1_emb.dtype) batch_idx = tf.tile(tf.expand_dims(tf.range(s[0]), 1), [1, s[1]]) V1 = tf.gather_nd(params=AAA, indices=tf.stack([batch_idx, V1_emb], axis=-1)) V2 = tf.gather_nd(params=AAA, indices=tf.stack([batch_idx, V2_emb], axis=-1))

.gitconfig

然后,[alias] w = "!reword() { git commit --amend -m \"$1\"; }; reword" like Andrew C proposed in his answer

据我所知,人们通常也将别名命名为x git w "..." ...

答案 4 :(得分:0)

完善的解决方案,支持更自然的语法。基于@AndrewC的工作。

pick 7c88fde9
x reword Integrated database module
pick 23b35c34 fix this and that
x reword 'configuration reads ${HOME} now'

将此脚本另存为以下路径中的“ reword”可执行文件:

#!/bin/sh
# In the git rebase todo list, directly reword commits. Save this script as "reword", executable, in the path.
# The message can be written literal or as one argument in double quotes. Use single quotes to not interpret ${HOME} `uname` etc.
git commit --amend -m "$*"