我如何定制git的合并提交信息? [英] how can I customize git's merge commit message?
问题描述
我的问题是,如何格式化git-fmt-merge-msg或者什么决定了这个自动化的消息(我可以在提交之后通过修改并使用git-log --pretty = format手动执行此操作: '...')
例如,我想将其格式化为:
合并分支'测试'
*测试:
[BZ:#123]第五个提交主题
[BZ:#123]第四次提交主题
[BZ:#123]第三次提交主题
[BZ:#123]第二次提交主题
[BZ:#123]第一次提交主题
合并详情:
[BZ:#123]第五次提交主题
于2010-06-30 11:29:00 +0100
- 第五次提交机构
[BZ:#123]第四次提交主题
于2010-06-30 11:22:17 +0100
- 第四个提交主体
[BZ:#123]第三次提交主题
于2010-06-30 11:21:43 +0100
- 第三次提交机构
[BZ:#123]第二次提交主题
于2010-06-30 11:21:30 +0100
- 第二次提交机构
[BZ:#123]第一次提交主题
于2010-06-30 11:29:57 +0100
- 第一次提交正文
编辑:
为非理想修复请参阅答案下面是
,但真正的问题是如何修改'fmt-merge-msg'生成的信息?
我发现解决这个问题的方法有两种
note :不要同时使用两个,就好像提交未能合并它会再次将日志添加到底部。
个人记录:我使用的是第一个解决方案,因为它完全依赖于git的钩子和配置属性,而不是外部脚本。
对于真正的解决方案,必须扩展git命令命名为'fmt-merge-msg',它在传递--log选项时生成oneline描述(如果您确实需要这种解决方案必须创建自己的补丁(用于git)并从源代码进行编译)。
1。使用prepare-commit-message作为VonC 建议
此解决方案存在的问题是您需要中断提交并手动提交
设置将构建的别名所需的提交信息:
[别名]
lm = log --pretty = format:'%s%n by %C(黄色)%an%Creset(%ad)%n%n%b'--date =本地
$ b $在$ GIT_DIR / hooks /(下面的示例脚本)中创建可执行的prepare-commit-msg来创建prepare-commit-msg钩子 p
$ b
#!/ bin / sh
#...
在
合并的情况下$ 2,$ 3)
echo合并详细信息:>> $ 1
echo>> $ 1
git lm ORIG_HEAD..MERGE_HEAD>> $ 1;;
*);;
esac
应该定义一个别名提交消息,例如
[别名]
m =合并--no-ff - 无提交
2。使用一个自动生成合并的自定义命令
(使用在1中创建的lm别名)
#!/ bin / sh
echo
echo合并提交细节 - HEAD .. $ 1
git merge --no-ff --no-log -m`git lm HEAD .. $ 1`--no-commit $ 1
<然后执行一个相当严格的命令:
./ cmd-name< branch to merge>
如果您仍然想要提交提交的oneline描述,您需要添加新的命令或无论是-m参数(如果你使用--log,它会在底部生成)
Every time I do a merge I need for a merge commit to be generated and I would like it to have more than just the summary of all the commits.
My question is how can I format git-fmt-merge-msg or what determines this automated message (I can do this manually after a commit by amending it and using git-log --pretty=format:'...')
For example I would like to format it as such:
Merge branch 'test'
* test:
[BZ: #123] fifth commit subject
[BZ: #123] fourth commit subject
[BZ: #123] third commit subject
[BZ: #123] second commit subject
[BZ: #123] first commit subject
Merge details:
[BZ: #123] fifth commit subject
at 2010-06-30 11:29:00 +0100
- fifth commit body[BZ: #123] fourth commit subject
at 2010-06-30 11:22:17 +0100
- fourth commit body[BZ: #123] third commit subject
at 2010-06-30 11:21:43 +0100
- third commit body[BZ: #123] second commit subject
at 2010-06-30 11:21:30 +0100
- second commit body[BZ: #123] first commit subject
at 2010-06-30 11:29:57 +0100
- first commit body
edit:
for non-ideal fix see answer below
but the real question is how to modify the information generated by the 'fmt-merge-msg'?
I've found there are two ways for solving this problem
note: don't use both at the same time, as if the commit fails to merge it will add the log again to the bottom.
personal note: I'm using the first solution as it relies entirely on git's hooks and config properties, instead of an external script.
For a real solution one would have to extend a git command named 'fmt-merge-msg' that generates the oneline descriptions when passing the --log option (if you really need this solution you'll have to create your own patch (for git) and compile it from source).
1. using prepare-commit-message as VonC suggested
this solution has the problem that you need to interrupt the commit and then commit manually
setting an alias that will build the desired commit message:
[alias]
lm = log --pretty=format:'%s%n by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local
creating the prepare-commit-msg hook by creating an executable prepare-commit-msg in $GIT_DIR/hooks/ (example script below)
#!/bin/sh
#...
case "$2,$3" in
merge,)
echo "Merge details:" >> $1
echo "" >> $1
git lm ORIG_HEAD..MERGE_HEAD >> "$1" ;;
*) ;;
esac
one should define an alias commit msg such as
[alias]
m = merge --no-ff --no-commit
2. using a custom command that will generate the merge automatically
(using the lm alias created in 1.)
#!/bin/sh
echo ""
echo "merge with commit details -- HEAD..$1"
git merge --no-ff --no-log -m "`git lm HEAD..$1`" --no-commit $1
and then execute a rather rigid command:
./cmd-name <branch to merge>
if you still wish to have the oneline description of the commits you'll need to add new commands or whatever to the -m argument (if you use --log then it will be generated on the bottom)
这篇关于我如何定制git的合并提交信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!