使用git rebase,是否有一种方法可以使用默认命令在git-rebase-todo中重新提交提交消息? [英] With git rebase, is there a way to reword commit messages in the git-rebase-todo using the default commands?

查看:85
本文介绍了使用git rebase,是否有一种方法可以使用默认命令在git-rebase-todo中重新提交提交消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我运行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一样),就像这样:

I would like to reword commit messages directly from this file, rather than editing each commit message one at a time (as per usual with reword), like so:

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来完成此操作,但是我似乎无法弄清楚该怎么做(即使可能的话).我已经能够通过

I had hoped that this could be done using just reword or edit, but I can't seem to figure out how (if even possible). I've been able to achieve the same result with

x git cherry-pick 6b24464 && git commit -amend "foo bar"

但是,这比我为大型基准所花费的时间要多.有什么想法吗?

However, this is more time consuming than I'd like for large rebases. Any ideas?

推荐答案

我不认为这是可以做到的,因为当您执行git rebase -i时,您只会得到每个提交消息的第一行,而不是完整的提交消息.

I do not believe that can be done, because when you do a git rebase -i you get only the first line of each commit message, not the full commit message.

按照约定,提交消息的第一行应仅是摘要,并在随后的行中包含有关更改的更多详细信息. 有关如何编写正确的提交消息的Linus Torvalds

As a convention, a commit message should have the first line be only a summary, and have more details about the change in the following lines. Here's Linus Torvalds on how to write a proper commit message

另外,请编写良好的git commit消息.一个好的提交消息看起来像这样:

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所假定的,因此它不会让您通过每次提交视图一行"来编辑提交消息.

So, even though you may have done only one line of message per commit, this is not what git is assuming, so it won't let you edit a commit message through a "one line per commit view".

这篇关于使用git rebase,是否有一种方法可以使用默认命令在git-rebase-todo中重新提交提交消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆