How do I fetch/re-push a submodule in git?

2019-02-20 08:59发布

问题:

In my git repository (Bitbucket) I have a reference to a sub project.

When I pushed it on the first place a .git/ folder was included (even though I use the repository only for backup so that'd not been really needed).

Now I have a reference to that submodule in the repository

 <folder_name> → <SHA> [<SHA>])
  • When I do git pull origin master the folder if fetched but it's empty.
  • When I try to put stuff in that folder (I removed it, then I pulled it from a different repository and then removed the .git/ folder to make it looks a normal folder, not a submodule) and then git add . && git commit -m ".." && git push origin master I only get Everything's up-to-date and of course nothing changed in the remote repository

Goal: push a past submodule as a normal folder part of the main repository.

What I missing out? How do submodules work? (the docs @ Github are not very clear to me)

回答1:

As I explained this morning in "How to solve this Git issue?", this (ie '<folder_name> → <SHA> [<SHA>]') is not a submodule.

A submodule is composed of:

  • a remote repo url (stored in a file called .gitmodules)
  • a SHA1 recorded as a gitlink (special entry in the index)

If you record only the SHA1, but not the url, you will have something like:

A git clone --recursive won't be able to clone the repo with that SHA1, because it does not know its url.

If you want to reference a subproject as a submodule:

  • read Git Submodules, and
  • use git submodule add https://...


标签: git bitbucket