0

我在git-notes --ref changelog开发时保留我的变更日志。我总是在 merge-to-master 提交上添加注释并将其推送到三个遥控器(git push <remote> refs/notes/changelog) - 但每次我忘记推送到一个遥控器并fetch从中推送时,引用都会被一些旧版本覆盖:

(对不起德语语言环境)

$ git fetch github -p
Von github.com:<user>/<repo>
 + ca36d98d...1f3b9041 refs/notes/changelog -> refs/notes/changelog  (Aktualisierung erzwungen)

如何防止这种情况?它与我的 有某种关系.git/config吗?

(摘自.git/config):

[remote "github"]
    url = git@github.com:<user>/<repo>.git
    fetch = +refs/heads/*:refs/remotes/github/*
    fetch = +refs/pull/*/head:refs/remotes/github/pr/*
    push = +refs/notes/changelog:refs/notes/changelog
    fetch = +refs/notes/changelog:refs/notes/changelog
[notes "rewrite"]
    rebase = true
    amend = true
[notes]
    rewriteRef = refs/notes/changelog
4

1 回答 1

2

你是对的。文件中的每一fetch行都.git/config指定了Git 将使用的许多默认 fetch refspecs之一,因此:

fetch = +refs/heads/*:refs/remotes/github/*
fetch = +refs/pull/*/head:refs/remotes/github/pr/*
fetch = +refs/notes/changelog:refs/notes/changelog

提供了三个这样的参考规范。

每个 refspec 由两个用冒号分隔的主要部分组成:左侧是源引用,右侧是目标引用。*可以使用星号并且其行为主要类似于 shell glob *(仅作为源;目标*被替换为与源*匹配的任何内容)。 如果这对以加号为前缀+,则始终强制更新(就像您--force在命令行上使用一样)。

请注意,远程跟踪名称如refs/remotes/github/master存在于每个远程空间中:您将origin获取master明显refs/remotes/origin/master不同于refs/remotes/github/master. 因此,至少对于所有普通目的而言,强制获取此类名称是安全的:您不能覆盖您自己的分支(位于 中)refs/heads/,也不能覆盖任何其他远程远程跟踪名称。

这当然不适用于 中的注释引用refs/notes/,也不适用于 中的标签refs/tags/,因此请谨慎使用+其中任何一个的前导。

于 2018-04-24T17:02:39.130 回答