注意:如果你想要在单次调用中从不同的refspec获取(暂时覆盖在配置中注册的fetch refspec),自Git 2.1(2014年8月)以来,你可以这样做。
参见
提交 c5558f8,由
Junio C Hamano(gitster
)提供。
自从远程跟踪分支的机会主义更新引入以来,始于
f269048(
fetch
:机会主义地更新跟踪引用,2013-05-11),在v1.8.4时代进行了一些更新,即使在命令行上给出了指定要获取的refspec,
remote.*.fetch
配置总是会启动,并且没有办法在每次调用时禁用或覆盖它。教导该命令注意
--refmap=<lhs>:<rhs>
命令行选项,可用于覆盖已配置的
remote.*.fetch
作为refmap。这提供了新选项:
--refmap=<refspec>
当从命令行获取列出的引用时,使用指定的refspec(可以多次给出)将引用映射到远程跟踪分支,而不是使用远程存储库的
remote.*.fetch
配置变量的值。
有关详细信息,请参见“配置的远程跟踪分支”部分。
(该Git“配置的远程跟踪分支”部分也来自Git 2.1:请参见“
难以理解git fetch
”)
在Git 2.25.1(2020年2月)中,“git fetch --refmap=”选项有了更好的文档。
参见提交 b40a502(2020年1月21日),由Derrick Stolee (derrickstolee
)执行。
(由Junio C Hamano -- gitster
--于提交4b69f29中合并,2020年1月30日)
fetch
: document and test --refmap=""
Signed-off-by: Derrick Stolee
To prevent long blocking time during a 'git fetch
' call, a user may want to set up a schedule for background 'git fetch
' processes.
However, these runs will update the refs/remotes branches due to the default refspec set in the config when Git adds a remote.
Hence the user will not notice when remote refs are updated during their foreground fetches. In fact, they may want those refs to stay put so they can work with the refs from their last foreground fetch call.
This can be accomplished by overriding the configured refspec using '--refmap=
' along with a custom refspec:
git fetch --refmap='' <remote> +refs/heads/*:refs/hidden/<remote>/*
to populate a custom ref space and download a pack of the new reachable objects.
This kind of call allows a few things to happen:
- We download a new pack if refs have updated. 2. Since the refs/hidden branches exist, GC will not remove the newly-downloaded data.
- With
fetch.writeCommitGraph
enabled, the refs/hidden refs are used to update the commit-graph file.
To avoid the refs/hidden directory from filling without bound, the --prune
option can be included. When providing a refspec like this, the --prune
option does not delete remote refs and instead only deletes refs in the target refspace.
Update the documentation to clarify how '--refmap=""
' works and create tests to guarantee this behavior remains in the future.
因此,
git fetch
选项手册页面现在包括:
--refmap=<refspec>:
When fetching refs listed on the command line, use the specified refspec (can be given more than once) to map the refs to remote-tracking branches, instead of the values of remote.*.fetch
configuration variables for the remote repository.
Providing an empty <refspec>
to the --refmap
option causes Git to ignore the configured refspecs and rely entirely on the refspecs supplied as command-line arguments.
See section on "Configured Remote-tracking Branches" for details.
请注意,过去7年左右我们对远程跟踪分支进行的更激进的更新没有体现在文档中,这已在Git 2.27(2020年第二季度)中得到纠正。
请参见
提交a440884,
提交f6a65de(由
Philippe Blain (phil-blain
)于2020年4月5日完成)。
(由Junio C Hamano -- gitster
--合并于提交fdee8b1,2020年4月22日)
拉取文档
:更正一个示例的过时描述
由Philippe Blain签署
自从f269048754 ("fetch
: opportunistically update tracking refs",2013年5月11日,Git v1.8.4-rc0 -- 合并 列在 批次 #0中),[
git pull](https://git-scm.com/docs/git-pull) <remote> <branch>
中的git fetch
会更新已配置的远程跟踪分支。
然而,在 git pull
文档的“示例”部分中,有一个示例仍然说明这不是情况。
更正此示例的描述。
所以,不要使用 git pull origin next
命令:
这会在 FETCH_HEAD 中暂时留下一个 next
的副本,但不会更新任何远程跟踪分支。
使用远程跟踪分支,可以通过调用 fetch 和 merge 命令来完成相同的操作:
现在你有:
这会在 FETCH_HEAD 中暂时留下一个 next
的副本,并且更新远程跟踪分支 origin/next
。
可以通过调用 fetch 和 merge 命令来完成相同的操作: