gpt4 book ai didi

git - 'git remote show'详解

转载 作者:太空狗 更新时间:2023-10-29 13:13:31 25 4
gpt4 key购买 nike

老实说,我找不到任何关于 git remote show 输出的详细文档(当然不在 man page 上)

特别是,对 Local 部分的清晰、准确的解释将不胜感激。

我觉得令人困惑的一个例子:

这里我有两个 Remote ,klasorigin 以及它们产生的输出:

> git remote show klas
* remote klas
Fetch URL: ..\klasrepo
Push URL: ..\klasrepo
HEAD branch: master
Remote branches:
experiment tracked
feature tracked
master tracked
pu tracked
stashbranch tracked
Local branch configured for 'git pull':
pu merges with remote pu
Local refs configured for 'git push':
experiment pushes to experiment (fast-forwardable)
feature pushes to feature (fast-forwardable)
master pushes to master (fast-forwardable)
pu pushes to pu (up to date)
> git remote show origin
* remote origin
Fetch URL: C:/Temp/git/.\barerepo.git
Push URL: C:/Temp/git/.\barerepo.git
HEAD branch: experiment
Remote branches:
experiment tracked
master tracked
Local branches configured for 'git pull':
experiment merges with remote experiment
master rebases onto remote master
Local refs configured for 'git push':
experiment pushes to experiment (up to date)
master pushes to master (fast-forwardable)

请注意,experimentmaster 列在both local refs configured for 'git push' 下。那是什么意思?我已经配置了 masterexperiment 分别跟踪 origin/masterorigin/experiment (和 pu 以跟踪 klas/pu)。

我的本​​地 feature 分支未设置为跟踪任何内容,但仍列在 local refs configured for 'git push' 下(唯一的连接似乎是同名,另一个非跟踪分支 foo,未提及)。 git push while on feature 给出 fatal: The current branch feature has no upstream branch. - 很难“快速转发”。

local refs configured for 'git push' 下列出本地分支的标准似乎是碰巧存在一个同名的远程分支??

供引用:

> git branch -vva
experiment 0cf7b2a [origin/experiment] added rand content 82 to .\rand_content.txt
* feature 4b25f46 added rand content 62 to bar.txt
foo 40aee50 added rand content 17 to .\rand_content.txt
master 4b25f46 [origin/master] added rand content 62 to bar.txt
pu 44ad10b [klas/pu] added rand content 51 to doo.txt
remotes/klas/experiment 1f4e89b app
remotes/klas/feature 884e953 added rand content 80 to bar.txt
remotes/klas/master 57877c1 added in tobias repo
remotes/klas/pu 44ad10b added rand content 51 to doo.txt
remotes/klas/stashbranch 8678cf0 added rand content 44 to .\rand_content.txt
remotes/origin/HEAD -> origin/master
remotes/origin/experiment 0cf7b2a added rand content 82 to .\rand_content.txt
remotes/origin/master 4b25f46 added rand content 62 to bar.txt
> git config --list --local | select-string 'branch|remote'
remote.origin.url=C:/Temp/git/.\barerepo.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.master.rebase=true
remote.klas.url=..\klasrepo
remote.klas.fetch=+refs/heads/*:refs/remotes/klas/*
branch.experiment.remote=origin
branch.experiment.merge=refs/heads/experiment
branch.pu.remote=klas
branch.pu.merge=refs/heads/pu
> git --version
git version 1.8.1.msysgit.1

最佳答案

这似乎是 Git 1.8.1 中的错误。

略读 Git 源代码(特别是 remote.cbuiltin/remote.c ),“为‘git push’配置的本地引用”下的列表计算如下:

  1. 收集配置的推送引用规范:
    • 阅读.git/remotes/<remotename> (一个过时的配置文件;参见 git help repository-layout )
    • 阅读.git/branches/<branchname> (另一个过时的配置文件)
    • 检查 remote.<remotename>.push配置项
  2. 如果第 1 步没有找到任何东西,请使用 :作为唯一的推送引用规范
  3. 找到与收集的推送 refspecs 匹配的所有 {local, remote} 分支组合

注意上面的算法没有关注branch.<branchname>.remote , branch.<branchname>.merge , 或 push.default .

在典型的使用模式下,上述算法中的第 1 步永远不会找到任何已配置的 refspec,因此 :将会被使用。该 refspec 是一个简单的匹配 refspec,因此具有典型用法 git remote show <remotename>将始终打印 <branchname> pushes to <branchname>如果有一个名为 <branchname> 的分支在本地和远程存储库中。

关于git - 'git remote show'详解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15626353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com