Git 强制推送遥控器后获取笔记

Git fetch notes after forced push on the remote

我找到了很多关于如何使本地分支看起来像远程分支的答案,但就我而言,我需要接受强制推送到远程的更改 refs/notes/commits

更改是使用 git notes add 进行的。使用 git push origin refs/notes/* -f.

更新了遥控器

我在本地有不同的 refs/notes/commits 历史记录。到目前为止,我一直在使用 git fetch origin "refs/notes/*:refs/notes/*" 将远程笔记更改集成到我的本地。在强行推动下,这两个历史现在脱节了。我想把我的扔掉,拿走他们的。

因为 refs/notes/commits 不是分支(对吗?)我不能使用 git pushgit checkout 输入它然后 git reset (再次,对吗?)。那么,我可以使用什么来使我的本地 refs/notes* 等同于远程 refs/notes/*

确实 refs/notes/commits 不是 分支 ,因为根据定义,所有分支名称都以 refs/heads/ 开头。但是,git fetchgit pushany ref-name 一起使用,您可以 force-fetch 以及 force-push。所以:

Until now I was using git fetch origin "refs/notes/*:refs/notes/*" to integrate remote notes changes to my local. With the forced push, the two histories are now disjoint. I want to throw away mine and take in theirs.

那将是强制获取。要强制获取,请执行与 git push 相同的操作:添加 --force 标志,或在 refspec 前面添加前缀——由冒号分隔的一对名称- 带有加号。后者更短(至少一个字符),所以我将在这里使用它:1

git fetch origin "+refs/notes/*:refs/notes/*"

或:

git fetch origin "+refs/notes/commits:refs/notes/commits"

这将用获取的值覆盖您 refs/notes/commits 的当前值(存储的哈希 ID),前提是它们有 refs/notes/commits* 的变体将用他们的 refs/notes/ 名称覆盖 all(创建他们之前没有的任何名称)。


1请注意,refspec 前面的 + 那个 refspec 设置了强制标志,而 [=命令行上的 20=] 为 all refspecs 设置强制标志。即:

git fetch origin refs/heads/br1:refs/heads/br1 +refs/heads/br2:refs/heads/br2

从原始分支 br1 获取到(本地)分支 br1 而不强制,但是从原始分支 br2 获取到 br2 with强迫。比较:

git fetch --force origin refs/heads/br1:refs/heads/br1 refs/heads/br2:refs/heads/br2

强制更新。即使 Git 的正常规则会拒绝更新,强制更新 也会发生。2

2对于git push,另一端可以添加附加,non-Git规则。例如,这就是 GitHub 和其他人提供“受保护分支”的方式。由于这些不是 Git 的正常规则,因此 --force+ 标志不会覆盖 这些 规则。 git fetch 没有任何等效项,因为它在 你自己的 存储库中,并且假定你知道自己在做什么。