为什么git子模块状态和我子模块git分支的输出不匹配?



我通过做git submodule --remote meta-dataset来确保我的项目正在使用hdb分支。但是当我cd到repo时,git submodule不同意git branch命令:

(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git ❯ git submodule update --init --recursive --remote meta-dataset
(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git ❯ git submodule status                                         
ca81edbf5093ec5ea1a1f5a4b31ec4078825f44b meta-dataset (arxiv_v1-200-gca81edb)

,然后我检查分支代码到子模块:

(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git ❯ cd meta-dataset 
(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git/meta-dataset ❯ git branch
* hdb

为什么他们不同意?

git版本号:

git version 2.37.0 (Apple Git-136)

命令git log --decorate --oneline --graph --all --branches显示:

*   ca81edb (HEAD -> master, origin/master, origin/HEAD) Merge pull request #86 from peymanbateni/main
|  
| * e3f90db Readme typo fixed.
| * 3cfb2b3 Semantic updates to table link entries.
| * 9ed89a1 Updated readme and leaderboard notebook.
| *   81794ed Merge branch 'main' of https://github.com/peymanbateni/meta-dataset
| |  
| | *   c5542c9 Merge branch 'google-research:main' into main
| | |  
| |_|/  
|/| |   
* | | 8fbfc63 Fix requirements typo
* | | d868ea1 Resolves #85
* | | 1e81d11 Internal change
| * | 1705427 Leaderboard script updated to handle multiple references for the same method.
| |/  
| * f725ab7 Update README.md
| * 717caf7 Update README.md
| * 1a3d45b Update README.md
| * 1542931 Update README.md
| * 81ae589 Update README.md
|/  
* 7cb980c Add new TSA and Simple/Transductive CNAPs results to the leaderboard.
* e12d61d Remove sources which have no training split from training instructions
:

奇怪的是它错过了它?

(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning/meta-dataset ❯ git branch --all
* master
remotes/origin/HEAD -> origin/master
remotes/origin/arxiv_v2_dev
remotes/origin/master

尽管我只是从头开始添加了一遍…


试做:

# - https://stackoverflow.com/questions/3796927/how-do-i-git-clone-a-repo-including-its-submodules/3796947#3796947
# - git submodule init initializes your local configuration file to track the submodules your repository uses, it just sets up the configuration so that you can use the git submodule update command to clone and update the submodules.
git submodule init
# - The --remote option tells Git to update the submodule to the commit specified in the upstream repository, rather than the commit specified in the main repository.
git submodule update --init --recursive --remote

再次

输出:

(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning ❯ git submodule init
# - The --remote option tells Git to update the submodule to the commit specified in the upstream repository, rather than the commit specified in the main repository.
git submodule update --init --recursive --remote
zsh: command not found: #
From github.com:brando90/meta-dataset
* [new branch]      hdb        -> origin/hdb
(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning ❯ 
(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning ❯ git submodule status
ca81edbf5093ec5ea1a1f5a4b31ec4078825f44b meta-dataset (arxiv_v1-200-gca81edb)
6e60161962ae3fa309335da7aa1c675c75ecca54 pytorch-meta-dataset (heads/hdb)

似乎有,但是git子模块状态没有显示


不工作,即使我试图针对特定的git子模块:

(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning ❯ git submodule update --init --recursive --remote meta-dataset
(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning ❯ git submodule status
ca81edbf5093ec5ea1a1f5a4b31ec4078825f44b meta-dataset (arxiv_v1-200-gca81edb)
6e60161962ae3fa309335da7aa1c675c75ecca54 pytorch-meta-dataset (heads/hdb)

它现在在那里:

(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning/meta-dataset ❯ git branch --all
* master
remotes/origin/HEAD -> origin/master
remotes/origin/arxiv_v2_dev
remotes/origin/hdb
remotes/origin/master

在子模块中,但它仍然在错误的分支上,即使我尝试git submodule update -romte它甚至与它的名称。


Ok, git子模块cmd def不认为项目在hdb分支上。我移动了他们,明确地把它结账了。它是自定义的,但submodule命令拒绝同意——即使我尝试多次重新更新它,重新添加它,并使用——remote获取它。

(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning ❯ cd meta-dataset 
(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning/meta-dataset ❯ git checkout hdb
branch 'hdb' set up to track 'origin/hdb'.
Switched to a new branch 'hdb'
(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning/meta-dataset ❯ git branch
* hdb
master
(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning/meta-dataset ❯ cd ..
(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning ❯ git submodule status  
ca81edbf5093ec5ea1a1f5a4b31ec4078825f44b meta-dataset (arxiv_v1-200-gca81edb)
6e60161962ae3fa309335da7aa1c675c75ecca54 pytorch-meta-dataset (heads/hdb)

裁判:

  • related:当我在.gitmodule文件中指定分支时,为什么我需要添加'——remote '到git's子模块?
  • 交叉:https://www.reddit.com/r/git/comments/102n08e/why_does_git_submodule_status_not_match_the/——交叉:https://www.quora.com/unanswered/Why-does-the-git-submodule-status-not-match-the-output-of-the-git-branch-of-my-submodule

答案其实很简单,你的子模块是在一个标签之后发生的一次提交。

通常情况下,阅读精彩的手册就会知道为什么会发生这种情况

git submodule status [--cached] [--recursive] [--] [<path>…​]

显示子模块的状态。这将为每个子模块打印当前签出的提交的SHA-1,以及子模块路径和SHA-1

git describe输出。

看一看git describe的手册就知道我们可以期望得到什么样的输出。

该命令查找从提交中可访问的最近的标签。如果标记指向提交,则只显示标记。否则,它会在标记对象和最近提交的缩写对象名称的顶部添加额外提交的数量作为标记名称的后缀。

所发生的是,它在标记对象的顶部添加了标记名称arxiv_v1的附加提交数量,然后在本地存储库的缩写提交SHA-1之后。

在示例部分,我们可以看到一个非常相似的东西。

用git之类的东西。git当前树,我得到:

[torvalds@g5 git]$ git describe parent
v1.0.4-14-g2414721

在您的示例中,git describe的输出是arxiv_v1-200-gca81edb,我们可以将其解析为

  • 前一个标签是arxiv_v1
  • 你正在提交ca81edb

现在到你没有说的问题:如何得到所有子模块的当前分支?答案很简单

git submodule foreach git branch --show-current