如何自定义git rebase --interactive commit消息的格式? [英] How do I customize the format of git rebase --interactive commit messages?

查看:102
本文介绍了如何自定义git rebase --interactive commit消息的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自己的本地工作中使用git(并且非常喜欢它),并且我遵循的工作流程类似于

I use git for my local work (and love it ever so much), and I follow a workflow similar to the one described in this article. So basically, when starting on a new feature, I create a branch for it, go through the usual hack then commit cycle, and when I think I'm done with it, I squash it into a single commit using git rebase --interactive master, and I always end up editing the multitude of commit messages into something looking like the example in the article, reproduced here:

[#3275] User Can Add A Comment To a Post

* Adding Comment model, migrations, spec
* Adding Comment controller, helper, spec
* Adding Comment relationship with Post
* Comment belongs to a User
* Comment form on Post show page

当然,这是在删除一堆#这是第x条提交消息行并在每条提交消息之前复制/粘贴 * 之后.

Of course, that's after a bunch of removing # This is the xth commit message lines and copy/pasting * in front of each commit message.

现在,我想知道的是,有什么方法可以自定义git rebase -i输出压缩的提交消息的方式,这样我就不必做所有的黑客工作了?

Now, what I was wondering, is there any way to customize how git rebase -i outputs the squashed commit messages so I don't have to do all that hacking?

(如果需要的话,我使用msysgit.我的编辑器是Notepad ++.)

(I use msysgit, if that matters. My editor is Notepad++.)

谢谢!

推荐答案

我认为没有办法(缺少源代码)来修改南瓜消息模板.但是,您有两种选择:

There's no way (short of hacking the source) to modify the squash message template, I don't think. However, you have a couple options:

  • 使用git log命令获取候选列表,类似于`git log --pretty ="*%s" commit-1..commit-2来获取项目符号.在Linux中,很有可能在编辑器中执行此操作-不知道msysgit的工作原理.

  • Use a git log command to get the shortlist, something like `git log --pretty="* %s" commit-1..commit-2 to get you your bullets. In linux it's very possible to do this from within your editor - don't know how that works with msysgit.

让您的编辑器为您完成工作!我不知道您的编辑器是什么,所以我不能真正告诉您该怎么做,但是在vim中肯定是很有可能的.(想法是:搜索/#这是.*提交消息/,删除几行,保留一行,最多删除下一条注释)

Have your editor do the work for you! I don't know what your editor is, so I can't really tell you what to do, but it'd certainly be very possible in vim. (The idea being: search for /# This is the .* commit message/, delete a couple lines, keep one, delete up to the next comment)

此外,在这种情况下,这可能不是您想要的,但是在git的最新版本中,可以使用 fixup 标识符代替壁球-它可以完成相同的操作,但是它会丢弃提交消息,因此,如果您一次提交带有实际消息的提交,然后是十个修复程序,则只需将它们标记为所有修复程序,而不必删除其一次性消息.

Also, it's not what you want in this case, probably, but in fairly recent versions of git, there's a fixup identifier that you can use instead of squash - it does the same thing, but it discards the commit message, so if you have one commit with the real message then ten fixes, you can just mark them all fixup and not have to delete their throwaway messages.

这篇关于如何自定义git rebase --interactive commit消息的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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