Is there a way to automatically merge notes if commits for those notes get squashed?

大城市里の小女人 提交于 2019-12-04 11:54:02

问题


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 

回答1:


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


来源:https://stackoverflow.com/questions/14585613/is-there-a-way-to-automatically-merge-notes-if-commits-for-those-notes-get-squas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!