(you'll notice a dirty message when the submodule changes).While Git submodules provide a powerful mechanism to structure your repositories and avoid code duplication, there are caveats! Submodules make checking out and committing code more complex and error-prone. Make sure that in the future, if you make changes to the submodule, that you also add them to the parent repository using git add. Just commit the changes and push them up, and your two projects should be re-synchronized. Next, if you run the git diff command you'll notice that although none of the files have changed in the main repository, you'll get a dirty message showing you that the submodule now points to a new commit. To ensure that your parent is pointing to the latest submodule commit (which is my case what I wanted), navigate into the submodule and run git pull and then return to the parent and run git add. In other words, your parent project could be pointing to the wrong commit of your submodule. The somewhat counterintuitive issue here (or at least it was for me is this): If the newest version of your main repository gets out-of-sync with your submodule, then when you try and "update" the submodule by running git submodule update from within the main repository, it will only pull up to the latest changes SPECIFIED IN THE PARENT, and not in the submodule. After this is done you can return to the parent repository and commit the change to the submodule to record the new submodule commit that you are now using for the submodule in the current version as well as future versions until you make another update. If you make any new commits or you pulled from a repository different from the one you use as the source for the submodule, make sure to push your changes out. To get a newer version of the submodule, switch into that directory and update it as you would any other git repository (e.g. This may actually be an older version than what you currently have checked out in that submodule, for instance if you are examining an old version of the parent repository which used an older version of the submodule. The git submodule update command is provided to update the checked out version of the submodule to the commit which is recorded for the current version of the parent repository. Updating a submodule to a different commit (doesn't have to be the latest) requires you to cd into that directory, manipulate it like a regular git repo so the current commit is what you want, then go back out and commit this change on the top level repo.Įach git commit which includes a submodule ties to a particular commit within the submodule repository. It really means "point the submodule to the commit that the parent repo's commit expects". The word "update" is not the best for this submodule command. Git commit -am "Updated submodule" # assumes you had no other modified files Git pull # assumes you are already on the branch you need to be on Git commit -m "Updated my solution to use latest sub project." Git status # should show that your submodule changed Git checkout master # or any other branch that you need the latest of What you need to do is: cd mysubmoduledir This way you can checkout another branch, older commit or tag, then run git submodule update and the submodule will be set to what that reference expects so your entire solution will have it's dependencies satisfied. git submodule update will set your submodule to what the current commit in the parent repo specifies the submodule should be at. Git is doing exactly what it's supposed to be doing.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |