Why does git submodule status not match the output of git branch of my submodule?
Asked Answered
M

1

0

I made sure that my project was using the hdb branch by doing git submodule --remote meta-dataset. But git submodule does NOT agree with the git branch command when I cd into the repo:

(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)

then I check the branch by cding into the submodule:

(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

why are they not agreeing?

Version of git:

git version 2.37.0 (Apple Git-136)

The command git log --decorate --oneline --graph --all --branches shows:

*   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
:

Weird it's missing it?

(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

despite me JUST adding it again from scratch...


tried doing:

# - https://mcmap.net/q/13651/-how-do-i-quot-git-clone-quot-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

again

output:

(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)

seems it there but git subomdule status doesn't show it.


Doesn't work even if I try to target the specific git submodule:

(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)

It's there now:

(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

in the submodule but it's still on the wrong branch even if I try git submodule update --romte it even with the name to it.


Ok the the git subomdule cmd def doesn't think the project is on the hdb branch. I moved their, checkout it out explicitly. It's def in it but the submodule command refuses to agree -- even when I try to re update it multiple times and re add it and git fetch it with --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)

Ref:

Mascia answered 3/1, 2023 at 20:41 Comment(4)
Same question: what version of Git are you using?Isotone
@Isotone git version 2.37.0 (Apple Git-136)Mascia
When you do a git log --decorate --oneline --graph --all --branches in the submodule folder, do you see both branches meta-dataset and hdb? Or are there referencing the same commit?Isotone
@Isotone I don't think it's showing the hdb branch...pasted the top of the output of the command you recommended.Mascia
M
1

The answer is actually super simple, your submodule is on a commit that happens some times after a tag.

As is often the case, reading the fantastic manual shows why this is happens

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

Show the status of the submodules. This will print the SHA-1 of the currently checked out commit for each submodule, along with the submodule path and the output of git describe for the SHA-1

having a look at git describe's manual tells us what exact kind of output we can expect.

The command finds the most recent tag that is reachable from a commit. If the tag points to the commit, then only the tag is shown. Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit.

What happens is that it suffixed the tag name arxiv_v1 with the number of additional commits on top of the tagged object, then followed by the abbreviated commit SHA-1 of the local repository.

On the examples section we can see a very similar thing.

With something like git.git current tree, I get:

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

In your case, git describe's output is arxiv_v1-200-gca81edb, we can parse it as

  • previous tag is arxiv_v1
  • you are 200 commits after it
  • you are on the commit ca81edb

Now onto the question you did not word: how to get your current branch for all submodules? The answer is simply

git submodule foreach git branch --show-current

Maniemanifest answered 8/1, 2023 at 14:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.