Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Submodules. Pulling into a new clone of the super-project

OK. So I thought I had this licked ... but now ....

I have a project which includes one small library from GitHub as a submodule. In the original version of that super-project the submodule is working as expected.

However, I just cloned the superproject, did what I thought I should : "git submodule init", got the directory of the submodule to appear, but it's empty.

If I now try to do

git submodule update 

I get

fatal: Needed a single revision  Unable to find current revision in submodule path 'external_libraries/BEACHhtml' 

If I try

git submodule foreach git pull 

I get

Entering 'external_libraries/BEACHhtml' fatal: Where do you want to fetch from today? Stopping at 'external_libraries/BEACHhtml'; script returned non-zero status. 

In my .git/config, I have this :

[submodule "external_libraries/BEACHhtml"]     url = [email protected]:interstar/BEACHhtml.git 

In my .gitmodules I have this :

[submodule "external_libraries/BEACHhtml"] path = external_libraries/BEACHhtml url = [email protected]:interstar/BEACHhtml.git 

Anyone got an idea what's missing?

like image 922
interstar Avatar asked Sep 30 '11 02:09

interstar


People also ask

Does git clone pull submodules?

It automatically pulls in the submodule data assuming you have already added the submodules to the parent project. Note that --recurse-submodules and --recursive are equivalent aliases.

Why you should not use git submodules?

This is because of some major drawbacks around git submodules, such as being locked to a specific version of the outer repo, the lacking of effective merge management, and the general notion that the Git repository itself doesn't really know it's now a multi-module repository.

How do you clone with submodules?

Git clone with submodules The list of steps required to clone a Git repository with submodules is: Issue a git clone command on the parent repository. Issue a git submodule init command. Issue a git submodule update command.

What does git pull -- recurse submodules do?

git submodule foreach git pull origin master or git pull origin master --recurse-submodules is what you want if you intend to update each submodule to the latest from their origin repositories. Only then will you get pending changes in the parent repo with updated revision hashes for submodules.


2 Answers

It seems that now (in 2019) installing latest GIT client could solve the problem according to comments below. This should be the best solution for now.


I have the same problem as you. This is a bug in git: http://git.661346.n2.nabble.com/BUG-git-submodule-update-is-not-fail-safe-td7574168.html

In short, for your problem, try:

# rm -rf external_libraries/BEACHhtml # git submodule update 

It seems there is something wrong with the previous checkout folder, remove it, and update again solves the problem.

like image 104
Han He Avatar answered Oct 01 '22 08:10

Han He


Solved by deleting 2 directories and refetching submodule:

  1. Go to external_libraries/BEACHhtml and look into .git file. It's content should be something like gitdir: ../../.git/modules/external_libraries/BEACHhtml
  2. Delete both external_libraries/BEACHhtml and .git/modules/external_libraries/BEACHhtml directories.

From now on git submodule update runs without errors.

like image 42
Lu55 Avatar answered Oct 01 '22 09:10

Lu55