为什么全局git配置“ remote.origin.push”会覆盖本地的“ remote.origin.push”?

埃尔皮·凯
# git version 2.22.0.windows.1

# create simulation repos
git init --bare server
git init client

# set global and local config
git config --global remote.origin.push refs/heads/*:refs/for/*
cd client
git remote add origin ../server
git config remote.origin.push refs/heads/*:refs/heads/*

# create and push "master"
touch a.txt
git add a.txt
git commit -m foo
git push origin master

预计本地refspecrefs/heads/master:refs/heads/master会起作用。但是refs/for/master创建。我删除refs/for/master并尝试-c

git push origin :refs/for/master
git -c remote.origin.push=refs/heads/*:refs/heads/* push origin master

再次refs/for/master创建而不是refs/heads/master

remote.origin.push在全局配置中删除,然后重试,然后refs/heads/master按预期创建。我还要进行这些测试。

global refs/heads/*:refs/for/*
local  refs/heads/*:refs/hello/*
result refs/for/master

global refs/heads/*:refs/hello/*
local  refs/heads/*:refs/for/*
result refs/hello/master

global refs/heads/*:refs/for/*
local  unset
result refs/for/master

global unset
local  refs/heads/*:refs/hello/*
result refs/hello/master

我什至在系统配置中添加了push refspec,这也会导致意外的结果。

system refs/heads/*:refs/world/*
global refs/heads/*:refs/hello/*
local  refs/heads/*:refs/heads/*
result refs/world/master

和测试user.name

system systemname
global globalname
local  localname
result localname

事实证明,remote.origin.push与其他配置变量相比,优先顺序相反。

我很困惑,因为它不能像我所相信的那样起作用。这是错误还是我错过了git config的任何细微功能?

bk2204

在这种情况下,并不是以不同的顺序读取配置,而是添加了推引用规范。换句话说,可以在其中指定多个push refspec选项remote.<remote>.push,它们全部以从配置文件中读取的顺序生效。

但是,Git只会将一组源引用推送到一个位置。由于您已经指定了目的地refs/heads/*(通过在较早的配置文件中列出),因此以后的目的地都不会覆盖它。您可以通过在命令行上同时列出两者来查看此内容:

$ git push $TMP/test-repo refs/heads/*:refs/for/* refs/heads/*:refs/heads/*
Enumerating objects: 105, done.
Counting objects: 100% (105/105), done.
Delta compression using up to 4 threads
Compressing objects: 100% (93/93), done.
Writing objects: 100% (105/105), 32.96 KiB | 3.00 MiB/s, done.
Total 105 (delta 41), reused 0 (delta 0)
remote: Resolving deltas: 100% (41/41), done.
To /tmp/user/1000/test-repo
 * [new branch]      master -> refs/for/master

因此,如果指定了全局配置文件,而指定了refs/tags/*:refs/tags/*本地配置文件refs/heads/*:refs/for/*,则两者都将生效,因为它们不会重叠。

如果在这种情况下需要其他行为,则需要删除全局和系统配置,或者在本地存储库中切换远程名称。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

什么是“ git remote add ...”和“ git push origin master”?

git push->代码仅查看当前更改(remote.origin.push覆盖push.default)

“为‘git push’配置的本地引用:”列在‘git remote show origin’的输出中是什么意思?

git push origin HEAD : remote_branch 和 git push origin local_branch:remote_branch 有什么区别?

为什么“在 Github 上共享项目”(来自 IntelliJ)有效,但“git push remote origin master”(来自终端)无效?

为什么git remote prune origin会删除我的本地标签?

git:git push -u origin origin:master

git remote update origin --prune对本地更改的影响

为什么git push origin master会绘制ASCII艺术?

“ git remote add origin”仅显示“ git remote add”的用法

git push origin master问题

当我尝试 git remote remove origin 时,为什么 Git 会告诉我“错误:没有这样的远程 'origin'”?

git命令中的“ origin”和“ remote”有什么区别?

为什么“ git push origin master”不起作用?

为什么“ git push origin @”不起作用?

“ git remote add origin”,“ set-url origin”和config ...有什么区别?

在本地删除<git>后,'git push origin <branch>'是否会远程删除它?

git remote prune origin不会删除本地分支,即使其上游远程分支已删除

git push origin HEAD和git push origin [current-branch-name]有什么区别?

Git: How to remove remote origin from Git repo

git remote set-url origin的Ansible等效项

命令 git push origin master 不工作

`git push origin master` 不起作用

git push origin master中的奇怪图像

Push Commit origin:master with git (android studio)

git push origin master不推送文件

git push和git push origin master之间的区别

为什么使用git push gerrit HEAD:refs / for / master而不是git push origin master

为什么在执行“ git push origin --delete BRANCHNAME”后“ git push”有效?