在从origin/base分支到我的feature分支进行合并之后,我不得不解决文件上的一个冲突Parameter.java.我启动了我的Git合并工具,我解决了它.解决之后,我执行了一个git commit并使用默认的合并提交消息打开了Vim.
事实是,这个默认提交消息包含冲突列表,但从一开始#,因此它们将在提交消息中被忽略.
Merge remote-tracking branch 'origin/base' into feature
# Conflicts:
# Parameter.java
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
# .git/MERGE_HEAD
# and try again.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch feature
# All conflicts fixed but you are still merging.
#
# Changes to be committed:
# modified: Parameters.java
# modified: SpecialParameters.java
# modified: Traveller.java
Run Code Online (Sandbox Code Playgroud)
是否有一些配置要添加以在提交消息中自动放置这些冲突行?因此删除部分中#冲突的文件Conflicts?
您可以使用prepare-commit-msg钩子来执行此操作.
复制.git/hooks/prepare-commit-msg.sample到.git/hooks/prepare-commit-msg
其中的示例实际上将#添加到Conflicts部分:
case "$2,$3" in
merge,)
/usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
Run Code Online (Sandbox Code Playgroud)
这个钩子很有意义,因为以前的版本默认是这样做的(比如in Linux git version 1.7.10.4).
现在你要做的恰恰相反:删除#冲突部分.实际上,git version 2.6.2.windows.1默认情况下注释掉了冲突部分,因此您可以使用以下命令更新命令prepare-commit-msg:
/usr/bin/perl -i.bak -ne 's/^#// if /^# Conflicts/ .. /^#\R/; print' "$1" ;;
Run Code Online (Sandbox Code Playgroud)
我找到了一种无需任何钩子或脚本即可执行此操作的方法:使用---cleanup scissors:
% git commit --cleanup scissors
Run Code Online (Sandbox Code Playgroud)
这会导致默认提交消息:
Merge branch 'branch'
# Conflicts:
# baz.txt
# foo.txt
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
# .git/MERGE_HEAD
# and try again.
# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# On branch master
# All conflicts fixed but you are still merging.
#
# Changes to be committed:
# modified: bar.txt
# modified: baz.txt
# modified: foo.txt
#
Run Code Online (Sandbox Code Playgroud)
如果你只是接受这一点,你会得到以下提交消息:
% git log -1
commit 64425eab687f9d4fc531da69495dcb401372104b (HEAD -> master)
Merge: efd152d 474a8f4
Author: Dave Dribin <dave@example.com>
Date: Fri Oct 19 23:47:19 2018 -0500
Merge branch 'branch'
# Conflicts:
# baz.txt
# foo.txt
Run Code Online (Sandbox Code Playgroud)
这不会删除#前缀,但它确实包含冲突文件的列表。为什么这样做?它将剪切特殊的“剪刀”行之后的所有内容,而不是注释字符串前缀。下面是该文件--cleanup scissors从git-commit(1) 手册页
--cleanup=<mode>
This option determines how the supplied commit message should be
cleaned up before committing. The <mode> can be strip, whitespace,
verbatim, scissors or default.
strip
Strip leading and trailing empty lines, trailing whitespace,
commentary and collapse consecutive empty lines.
whitespace
Same as strip except #commentary is not removed.
verbatim
Do not change the message at all.
scissors
Same as whitespace except that everything from (and including)
the line found below is truncated, if the message is to be
edited. "#" can be customized with core.commentChar.
# ------------------------ >8 ------------------------
default
Same as strip if the message is to be edited. Otherwise
whitespace.
The default can be changed by the commit.cleanup configuration
variable (see git-config(1)).
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2913 次 |
| 最近记录: |