gpt4 book ai didi

git 在 merge 冲突后更改 change-id 的位置

转载 作者:太空狗 更新时间:2023-10-29 14:43:55 28 4
gpt4 key购买 nike

我正在使用 gitgerrit 一段时间,但有一个行为让我很烦。

如果我使用冲突进行cherry-pickmerge,则change-ID初始化by commit-msg hook 不在最后一行。这里有一个例子。

Commit message

Change-ID: AAAAAAAAAA

Conflits:
File1.cpp

如果我保持这样的消息,push 会被 gerrit 禁止,它会在最后一段中显示。

我知道可以使用 --amendinteractive rebase 编辑提交消息,但我不想这样做。我想让 git 单独处理它。

我的问题很简单。有没有办法通过在 Change-ID 之前插入来制作冲突行?


Git 版本 1.8.1

最佳答案

解决这个问题的两种方法:

(I) prepare-commit-msg 钩子(Hook)

使用这个钩子(Hook)的步骤:

  1. 复制现有示例:cp .git/hooks/prepare-commit-msg.sample .git/hooks/prepare-commit-msg

  2. 确保 Hook 具有正确的权限:chmod 755 .git/hooks/prepare-commit-msg

这是为了防止你在 .git/hooks 中没有它:

#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source. The hook's purpose is to edit the commit
# message file. If the hook fails with a non-zero status,
# the commit is aborted.
#
# To enable this hook, rename this file to "prepare-commit-msg".

# This hook includes three examples. The first comments out the
# "Conflicts:" part of a merge commit.
#
# The second includes the output of "git diff --name-status -r"
# into the message, just before the "git status" output. It is
# commented because it doesn't cope with --amend or with squashed
# commits.
#
# The third example adds a Signed-off-by line to the message, that can
# still be edited. This is rarely a good idea.

case "$2,$3" in
merge,)
/usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;

# ,|template,)
# /usr/bin/perl -i.bak -pe '
# print "\n" . `git diff --cached --name-status -r`
# if /^#/ && $first++ == 0' "$1" ;;

*) ;;
esac

# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"

接下来的一点应该注释掉 Conflict 部分,而您不必费心升级 git 本身。

case "$2,$3" in
merge,)
/usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;

(二)升级git到2.1.3+

参见 commit 96f78d3
(由 Junio C Hamano -- gitster -- 于 2014 年 10 月 28 日 merge )

查看提交历史:

49c3e92 (tag: refs/tags/v2.1.3) Git 2.1.3
ebc2e5a Merge branch 'jk/pack-objects-no-bitmap-when-splitting' into maint
9db1838 Merge branch 'da/mergetool-meld' into maint
af1b4e3 Merge branch 'rm/gitweb-start-form' into maint
27c31d2 Merge branch 'bc/asciidoc-pretty-formats-fix' into maint
a8f01f8 Merge branch 'rs/daemon-fixes' into maint
5b509df Update draft release notes to 2.2
9ce57f1 Merge branch 'da/difftool'
e82935d Merge branch 'rb/pack-window-memory-config-doc'
7654ca6 Merge branch 'mg/lib-gpg-ro-safety'
ce71c1f Merge branch 'dm/port2zos'
c1777a2 Merge branch 'oc/mergetools-beyondcompare'
d70e331 Merge branch 'jk/prune-mtime'
853878d Merge branch 'bc/asciidoctor'
96ef1bd api-run-command: add missing list item marker
8828f29 use child_process_init() to initialize struct child_process variables
5d222c0 receive-pack: avoid minor leak in case start_async() fails
261f315 merge & sequencer: turn "Conflicts:" hint into a comment

从 v. 2.1.3 开始,该更改应该成为 Git 的一部分。因此,如果您升级到 git 版本 2.1.3+,“冲突”应该被自动注释掉,使“Change-Id”成为提交消息的最后一行,从而解决您的问题。

关于git 在 merge 冲突后更改 change-id 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39977033/

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