How to pull a new submodule

Tried looking for answers on this site and others: StackOverflow - Easy way pull latest of all submodules

They all seem to want to talk about if you are controlling them, not if someone else added one, and I just want to pull the additional one into my project without having to stash or backup my changes if I need to delete the folder.

Should I delete the .gitmodules file, and/or the submodule directories that I have already pulled down with git clone --recursive ? (StackOverflow - How to git clone including submodules?)

These commands do not seem to help either:

  • git submodule update --init --recursive seems like it did nothing.
  • git submodule update --recursive nothing.
  • git fetch --recurse-submodules output Fetching submodule ... several times.
  • git pull --recurse-submodules output the same thing, and then said Already up-to-date. after the fetch trial. Strange since in either case my submodules were already downloaded.
  • git clone --recursive ... Not tried yet. I feel like would overwrite any changes I have made, in the Stash or otherwise.
  • git submodule update --recursive --remote checked out a new commit SHA for one of the submodules.
  • git submodule update --recursive checked out a new commit SHA for one of the submodules. Could be the older, original commit level.
  • git submodule status gives the appropriate SHA, version, and name information for each, while still lacking the one that I want.
  • git submodule foreach git pull origin master
  • git submodule update does nothing.
  • I have been double-checking the library directory manually each time to make sure whether the additional submodule appeared or not.

    I want to avoid performing certain actions, unless they are not destructive to my current repository state containing code changes, and solves my problem, in case it is a command I have mentioned but did not run, or anyone else has another to try.

    I could try some of these with more effort, but I think I want to stop messing with them for now, and since I have not found the answer to this issue after doing some online searching, maybe the hopeful and eventual answer would help others anyway.

    Am I suffering from the con mentioned here at all? Software Engineering - Git submodule vs Git clone

    More links:

  • StackOverflow - Update Git submodule to latest commit on origin

  • git submodule update --init local/path/to/submodule/folder
    

    Best suggestion I have received so far is to run this command:

    git submodule add <URL_to_submodule> <local_path_to_place_submodule>
    

    So it looks to be what the other contributor would have done, that I would do again, even though it already exists in the remote.

    I guess this doesn't technically update the .gitmodules file from the remote's data like what would be expected, but haven't found a way to do that yet.

    Credit for the help goes to @pandatrax.

    Update

    Before trying the add method, I tried 1 more idea that involved copying the .gitmodules file from the remote manually and trying any of the update commands, but sadly that approach did not work either. It may have gone differently if I executed the commands in the root, since I was in a subfolder, but I doubt it.

    Then I used the add method, which downloaded the dependency, but the .gitmodules file showed changes. Once I set-up the GitHub remote and pulled from it after discarding that file, the project seems to be in a better state now, even syncing the commit SHAs for the updated module or 2, either since they matched, or it was overwritten.


    You have to do two things:

  • Do git pull in your main repository which holds the submodules. This will add the new submodule as an empty directory.
  • Do git submodule update --recursive --remote in the main repository. This will pull the latest changes for all submodules, including the new one.
  • This works at least in Git 2.13. Also note that if the repositories and submodules are on GitHub, you have to make sure you have access rights to them (if they are private).

    链接地址: http://www.djcxy.com/p/92384.html

    上一篇: 奇怪的问题与GIT回购?

    下一篇: 如何拉一个新的子模块