[英]Git fetch notes after forced push on the remote
I am finding a lot of answers to how to make a local branch look like a remote branch, but in my case, I need to take in changes that were force pushed to the remote to refs/notes/commits
.我找到了很多关于如何使本地分支看起来像远程分支的答案,但就我而言,我需要接受强制推送到远程的更改refs/notes/commits
。
The changes were made using git notes add
.更改是使用git notes add
进行的。 The remote was updated using git push origin refs/notes/* -f
.使用git push origin refs/notes/* -f
更新了遥控器。
I have different history for refs/notes/commits
locally.我在本地有不同的refs/notes/commits
历史记录。 Until now I was using git fetch origin "refs/notes/*:refs/notes/*"
to integrate remote notes changes to my local.到目前为止,我一直在使用git fetch origin "refs/notes/*:refs/notes/*"
将远程笔记更改集成到我的本地。 With the forced push, the two histories are now disjoint.在强行推动下,这两个历史现在脱节了。 I want to throw away mine and take in theirs.我想扔掉我的,接受他们的。
Since refs/notes/commits
is not a branch (right?) I cannot use git push
or git checkout
to enter it and then git reset
(again, right?).由于refs/notes/commits
不是分支(对吗?)我不能使用git push
或git checkout
进入它然后git reset
(再次,对吗?)。 So, what can I use to make my local refs/notes*
equivalent to the remote refs/notes/*
?那么,我可以使用什么来使我的本地refs/notes*
等同于远程refs/notes/*
?
It's true that refs/notes/commits
is not a branch , as all branch names by definition start with refs/heads/
instead.确实refs/notes/commits
不是branch ,因为根据定义,所有分支名称都以refs/heads/
开头。 However, git fetch
and git push
work with any ref-name, and you can force-fetch as well as force-push.但是, git fetch
和git push
可以与任何引用名称一起使用,您可以强制获取和强制推送。 So:所以:
Until now I was using
git fetch origin "refs/notes/*:refs/notes/*"
to integrate remote notes changes to my local.到目前为止,我一直在使用git fetch origin "refs/notes/*:refs/notes/*"
将远程笔记更改集成到我的本地。 With the forced push, the two histories are now disjoint.在强行推动下,这两个历史现在脱节了。 I want to throw away mine and take in theirs.我想扔掉我的,接受他们的。
That would be a forced fetch.那将是强制获取。 To force a fetch, do the same thing you do with git push
: add the --force
flag, or prefix the refspec —the pair of names separated by a colon—with a plus sign.要强制获取,请执行与git push
相同的操作:添加--force
标志,或在refspec (由冒号分隔的一对名称)前加上加号。 The latter is shorter (by at least one character) so that's the one I'll use here: 1后者更短(至少一个字符),所以我将在这里使用: 1
git fetch origin "+refs/notes/*:refs/notes/*"
or:或者:
git fetch origin "+refs/notes/commits:refs/notes/commits"
This will overwrite the current value (stored hash ID) of your refs/notes/commits
with the fetched value, provided they have a refs/notes/commits
;这将用获取的值覆盖您的refs/notes/commits
的当前值(存储的 hash ID),前提是它们有refs/notes/commits
; the variant with *
will overwrite all of your refs/notes/
names with theirs (creating any names they have that you didn't before).带有*
的变体将用他们的覆盖您所有的refs/notes/
名称(创建他们之前没有的任何名称)。
1 Note that +
in front of a refspec sets the force flag for that one refspec , while --force
on the command line sets the force flag for all refspecs. 1请注意,refspec 前面的+
为该refspec 设置强制标志,而命令行上的--force
为所有refspec 设置强制标志。 That is:那是:
git fetch origin refs/heads/br1:refs/heads/br1 +refs/heads/br2:refs/heads/br2
fetches from origin's branch br1
to (local) branch br1
without forcing, but fetches from origin's br2
to br2
with forcing.不强制从原点的分支br1
获取到(本地)分支br1
,但强制从原点的br2
获取到br2
。 Compare with:与之比较:
git fetch --force origin refs/heads/br1:refs/heads/br1 refs/heads/br2:refs/heads/br2
which forces both updates.这会强制更新。 A forced update simply takes place even if Git's normal rules would reject the update.即使 Git 的正常规则会拒绝更新,强制更新也会简单地发生。 2 2个
2 For git push
, the other end can add additional, non-Git rules . 2对于git push
,另一端可以添加额外的非 Git 规则。 That's how GitHub and others provide "protected branches", for instance.例如,这就是 GitHub 和其他人提供“受保护分支”的方式。 Since these are not Git's normal rules, the --force
or +
flag does not override these rules.由于这些不是 Git 的常规规则,-- --force
或+
标志不会覆盖这些规则。 There's nothing equivalent for git fetch
, since that's into your own repository and you are assumed to know what you are doing. git fetch
没有任何等效项,因为它在您自己的存储库中,并且假定您知道自己在做什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.