gpt4 book ai didi

Git 默认 merge 提交消息不包括冲突

转载 作者:IT王子 更新时间:2023-10-29 00:53:55 26 4
gpt4 key购买 nike

origin/base 分支 merge 到我的 feature 分支后,我必须解决文件 Parameter.java 上的一个冲突>。我启动了我的 Git merge 工具并解决了它。问题解决后,我执行了 git commit 并使用默认 merge 提交消息打开了 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

是否有一些配置要添加以将这些冲突行自动放入提交消息中?因此,要删除 Conflicts 部分中冲突文件的 # 吗?

最佳答案

我找到了一种无需任何钩子(Hook)或脚本即可执行此操作的方法:使用 ---cleanup scissors:

% git commit --cleanup scissors

这会导致默认提交消息:

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
#

如果您只是接受它,您会收到以下提交消息:

% 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

这不会删除 # 前缀,但会包含冲突文件列表。为什么这行得通?它会在特殊的“剪刀”行之后 剪切所有内容,而不是注释字符串前缀。这是 --cleanup scissors 的文档,来自 git-commit(1) man page

       --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)).

关于Git 默认 merge 提交消息不包括冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34899662/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com