如果提交这些笔记的提交被压缩,是否有办法自动合并笔记? [英] Is there a way to automatically merge notes if commits for those notes get squashed?

查看:156
本文介绍了如果提交这些笔记的提交被压缩,是否有办法自动合并笔记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

  git commit -amSomething
git notes append -mDark
git commit -amSomething
git notes append -mSide

git rebase -i
#现在我压缩了两个提交,我期望看到黑暗面在这里
#但它表明钞票是未定义的
git notes show


解决方案

问题几乎肯定是你的配置;假设你有其他的默认配置,你需要将 notes.rewriteRef 选项设置为 refs / notes / commits

您需要的魔法命令是:

  git config notes.rewriteRef refs / notes / commitits 

在上述之后,挤压提交应该加入两个笔记。



然而,它们之间会有换行符;我怀疑禁用了这种行为,所以你把东西放在同一行,就像在你的例子中需要在Git源代码中进行黑客攻击一样。



背景



git help config (强调我的):


notes.rewriteRef


在重写过程中复制笔记时,指定应复制其笔记的(完全限定)参考。 ref可能是一个glob,在这种情况下,所有匹配参考文件中的备注都将被复制。您也可以多次指定此配置。



没有默认值;您必须配置此变量以启用音符重写。 将其设置为 refs / notes / commits 以启用对默认提交记录的重写。

此设置可以用 GIT_NOTES_REWRITE_REF 环境变量覆盖,该变量必须是以冒号分隔的参考或球体列表。



(另请参阅 notes.rewriteMode 注释的说明。重写。< command> ,它们都默认为我们需要的值,即 concatenate true

示例



以上测试类似:

  $ git init 
初始化的空的Git仓库

$ git config notes.rewriteRef refs / notes / commitits

$ git add a#这是我之前创建的文件

$ git commit -am'初始提交'
[master(root-commit)93219cb] Initial提交
1个文件已更改,1个插入(+),0个delet离子( - )
创建模式100644 a

$ echo a>> a

$ git commit -am'Something'
[master 3c17aca]
1个文件改变,1个插入(+),0个删除( - )

$ git notes append -m'Dark'

$ echo b > a

$ git commit -am'某物'
[master 6732d81]某物
1个文件已更改,1个插入(+),0个删除( - )

$ git notes append -m'Side'

$ git rebase -i HEAD〜2#将最后一个提交压缩到之前的提交并接受默认提交消息。
[detached HEAD 552668b]
1个文件已更改,2个插入(+),0个删除( - )
已成功重新更新并更新了裁判/头像/主控。

$ git show
commit 552668b4b96e4b2f8fcd7763dcc115edd159eb89(HEAD,master)
作者:me_and< not.an@email.address>
日期:Wed Jan 30 10:09:10 2013 +0000

某物

某物

注意:
黑暗

Side

diff --git a / ab / a
索引7898192..4ac2bee 100644
--- a / a
+++ b / a
@@ -1 +1,3 @@
a
+ a
+ b


For example:

git commit -am "Something"
git notes append -m "Dark "
git commit -am "Something"
git notes append -m "Side"

git rebase -i
# now I squash two commits and I expect to see "Dark Side" here
# but it show that note is undefined
git notes show 

解决方案

The problem is almost certainly your config; assuming you have otherwise default config, you need to set the notes.rewriteRef option to refs/notes/commits for this to work.

The magic command you need is thus:

git config notes.rewriteRef refs/notes/commits

After the above, squashing the commits should join the two notes.

They will have newlines between them, however; I suspect disabling that behaviour so you get things on the same line as in your example would require hacking around in the Git source code.

Background

From git help config (emphasis mine):

notes.rewriteRef

When copying notes during a rewrite, specifies the (fully qualified) ref whose notes should be copied. The ref may be a glob, in which case notes in all matching refs will be copied. You may also specify this configuration several times.

Does not have a default value; you must configure this variable to enable note rewriting. Set it to refs/notes/commits to enable rewriting for the default commit notes.

This setting can be overridden with the GIT_NOTES_REWRITE_REF environment variable, which must be a colon separated list of refs or globs.

(See also the descriptions for notes.rewriteMode and notes.rewrite.<command>, both of which default to the values we need, ie concatenate and true respectively.)

Example

Here's something similar for the above test:

$ git init
Initialized empty Git repository

$ git config notes.rewriteRef refs/notes/commits

$ git add a # Here's a file I created earlier

$ git commit -am 'Initial commit'
[master (root-commit) 93219cb] Initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 a

$ echo a >>a

$ git commit -am 'Something'
[master 3c17aca] Something
 1 files changed, 1 insertions(+), 0 deletions(-)

$ git notes append -m 'Dark '

$ echo b >>a

$ git commit -am 'Something'
[master 6732d81] Something
 1 files changed, 1 insertions(+), 0 deletions(-)

$ git notes append -m 'Side'

$ git rebase -i HEAD~2 # Will squash the last commit into the one before and accept the default commit message.
[detached HEAD 552668b] Something
 1 files changed, 2 insertions(+), 0 deletions(-)
Successfully rebased and updated refs/heads/master.

$ git show
commit 552668b4b96e4b2f8fcd7763dcc115edd159eb89 (HEAD, master)
Author: me_and <not.an@email.address>
Date:   Wed Jan 30 10:09:10 2013 +0000

    Something

    Something

Notes:
    Dark

    Side

diff --git a/a b/a
index 7898192..4ac2bee 100644
--- a/a
+++ b/a
@@ -1 +1,3 @@
 a
+a
+b

这篇关于如果提交这些笔记的提交被压缩,是否有办法自动合并笔记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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