默认设置的"refspec"用于"git push" [英] default set of "refspec" for "git push"

查看:97
本文介绍了默认设置的"refspec"用于"git push"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此之前,我认为git fetchgit push$GIT_DIR/config的影响是相同的,因为这两个都是repository engagements的命令,但是当我们为当前存储库添加存储库作为remote repository时,Git会创建configgit fetch的默认refspec集,例如:

Before this, I thought the effect of git fetch and git push on $GIT_DIR/config are the same, because both are commands for repository engagements but when we add a repository as remote repository for current repository, Git creates a default set of refspec for git fetch in config, for example like this:

fetch = +refs/heads/*:refs/remotes/remote_repository/*

为什么配置文件中的git push的默认refspec默认设置不相同?

Why does not do the same for default set of refspec for git push in config file?

我想差异是由default命令目的引起的:

I guess difference is caused by default purpose of commands:

  • fetch的默认用途用于downloading all objects and refs from another repository
  • push的默认用途是updating specific remote refs along with associated objects
  • Default purpose offetch is for downloading all objects and refs from another repository
  • Default purpose ofpush is updating specific remote refs along with associated objects

但是我不确定我的猜测.是真的吗?

But I am not sure in about my guess. Is it true?

推荐答案

简而言之,分支可以从一个远程跟踪分支中提取并推送到另一个.

Simply put, a branch can pull from one remote tracking branch and push to another.

即使您设置了默认的推送策略(git config push.default),也会被本地branch.<name>.push配置覆盖.

Even if you set a default push policy (git config push.default), that would be overridden by a local branch.<name>.push config.

由于git 2.5 ,您可以轻松地区分用于提取和推送的refspec(如果没有推送refspec对于分支,默认为提取一个)

Since git 2.5, you can differentiate easily between the refspec used for fetch and push (if there is no push refspec for a branch, it defaults to the fetch one)

例如,如果您在master分支上,并且想查看与要推送到的远程跟踪分支相比是领先还是落后(默认情况下为origin/master,但如果是其他远程分支,则为origin/master branch.master.push在配置中设置)

For instance, if you are on your master branch and want to see if you are ahead or behind compare to the remote tracking branch you are pushing to (by default, origin/master, but it could be any other remote one if branch.master.push is set in the config)

git for-each-ref --format="%(push:track)" refs/heads

快捷方式<branch>@{push}直接引用在配置branch.master.push中设置的值.

The shortcut <branch>@{push} refers directly to the value set in the config branch.master.push.

例如,要查看尚未推送的提交:

For instance, to see the commits you haven't pushed yet:

git log @{push}..


请注意,在之前 Git 2.22(2019年第二季度)中,--format选项中用于git for-each-ref%(push:track)令牌和朋友未显示正确的分支.
此问题已解决.


Note that before Git 2.22 (Q2 2019), the %(push:track) token used in the --format option to "git for-each-ref" and friends was not showing the right branch.
This has been fixed.

请参见提交c646d09 (2019年4月16日)通过 Junio C Hamano-gitster-

See commit c646d09 (16 Apr 2019) by Damien Robert (DamienRobert).
(Merged by Junio C Hamano -- gitster -- in commit f560a4d, 08 May 2019)

ref-filter:为%(push:track)

使用正确的分支

ref-filter.c中,当处理原子%(push:track)时, 前面/后面的值是使用stat_tracking_info计算的,它引用 到上游分支.

ref-filter: use correct branch for %(push:track)

In ref-filter.c, when processing the atom %(push:track), the ahead/behind values are computed using stat_tracking_info which refers to the upstream branch.

通过在stat_tracking_info中引入新的标志for_push修复此问题 在remote.c中,它执行相同的操作,但对于push分支.
更新stat_tracking_info的几个调用方以处理此标志.这 确保以后我们每次使用此功能时,请务必谨慎 指定是应应用于上游还是推送分支.

Fix that by introducing a new flag for_push in stat_tracking_info in remote.c, which does the same thing but for the push branch.
Update the few callers of stat_tracking_info to handle this flag. This ensure that whenever we use this function in the future, we are careful to specify is this should apply to the upstream or the push branch.

这篇关于默认设置的"refspec"用于"git push"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆