![]() To define the submodules for the various GT Theme components, add the following sections to the. This lets you clone another repository into your project and keep your commits separate. git metadata folder (make sure you have backup of this): rm -rf submodulepath/. gitmodules file or if you have more than one submodules edit this file removing the submodule from the list: git rm. # remove -allow-unrelated-histories if using git older than 2.9.Submodules allow you to keep a Git repository as a subdirectory of another Git repository. git rm -cached submodulepath (no trailing slash) Delete the. Git commit -m "Removed submodule sub_repo_path in preparation for merge"Īnd finally, just merge them git fetch. Now remove the subrepo from the main repo cd. Must be run from the root of a git repository"ĭeclare path="$(git config -f. >&2 echo "Error: No git repository found. Read -p "$(tput setaf 4)$1 (y/n) $(tput sgr0)"Ĭat &2 echo "Error: No submodule specified" # entire process and cleans up a few other corner cases.Įcho "Merge a submodule into a repo, retaining file history."Įcho " -v, -verbose Display verbose output" ![]() # post "Integrating a submodule into the parent repository", but automates the # This script builds on the excellent work by Lucas Jenß, described in his blog Git-submodule-rewrite: #!/usr/bin/env bash git submodule add the syntax to add a Git submodule lib/Room the path where the submodule repository will be added to in the House repository (optional). The latest code will be maintained with bugfixes on github at, but for the sake of proper stackoverflow answer protocol, I've included the solution in its entirety below. It builds on the excellent work by Lucas Jenß, described in his blog post " Integrating a submodule into the parent repository", but automates the entire process and cleans up a few other corner cases. Git does not download submodule contents by default, so make sure to include this information in your README. So all I am saying is that newbies might be looking for some clarification: 1) If you add the submodule to a project you are working on, then that submodule’s contents will be cloned and checked out. If your team is not used to this Git structure, they most likely won’t know how to clone or handle them correctly. However if you add a submodule to the repository in the manner you state above, the contents of that repository will in fact be there. So, clone without recursive, then git submodule init, then use sed to change the urls to the read-only form, then git submodule update.If you are not going to be contributing to fuel, you might as well just use the read-only form of the url and the server will be able to pull it down. Need to specify the use of Git Submodules in instructions. For this example, I’m using two libraries. It's also a very easy one-line invocation that does all of the work for you. You dont have a key on that machine to connect to github. These libraries are hosted on GitHub by their maintainers as independent projects. It doesn't suffer from the git log -follow issues that the other solutions suffer from. I've created a script that will translate a submodule to a simple directory, while retaining all file history. If you still have problems with git log, try some options (e.g., -follow, -M, -C) which do better rename and copy detection. In fact, what happens here is just a renaming of many files inside one repository, and Git should automatically detect this. But it won’t cause any problems for Git.Ī big advantage of this second solution is that you can still run git blame or git log on the files which were originally in submodules. The resulting repository will look a bit weird: there will be more than one initial commit. Git rm -cached submodule_path # delete reference to submodule HEAD ![]() Git merge -s ours -no-commit submodule_origin/master ![]() This is more flexible and straightforward than copying and pasting, as you won’t need to periodically go back and paste in updated code for multiple projects. When you add your component as a submodule, you can easily update it in multiple repositories. # Start a fake merge (won't change any files, won't commit anything) Additionally, you can reuse a component youve created across multiple projects. Git remote add submodule_origin git://url/to/submodule/origin In the main module you will need to do the following: # Fetch the submodule commits into the main repository If you also want to preserve the history of the submodule, you can do a small trick: “merge” the submodule into the main repository, so that the result will be the same as it was before, except that the submodule files are now in the main repository. Git add submodule_path # will add files instead of commit reference Rm -rf submodule_path/.git # make sure you have backup!! # you need to edit this file instead of deleting! gitmodules # if you have more than one submodules, If all you want is to put your submodule code into the main repository, you just need to remove the submodule and re-add the files into the main repo: git rm -cached submodule_path # delete reference to submodule HEAD (no trailing slash)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |