I'm working on a Rust project that required me to vendor (i.e. fork for use solely with this project) one of the libraries it depends on. To do this, I cloned the git repo of the module I wanted to vendor to a subdirectory of my project, made my changes, and committed them to my local copy of that git repo (which I will call the inner repo). This is now a submodule of the git repo of my project (the outer repo). I would like to flatten them to a single repo. I do not think the changes I've made to this library's code are generally useful enough to warrant publishing as a separate git repo (which is a fancy way of saying it's a horribly messy hack that barely works for my use case), so I would rather have it be an ordinary folder inside the outer repo rather than something I have to clone separately.
I could do this by rm -rf submodule/.git
and then git add
ing the directory from the outer git repo, but that would discard the commit history of the inner repo. What I would like to do is replay the commits of the inner git repo onto the outer one. My desired end state is for all of the commits I have made to the submodule (but not the commits that were made before I forked it) to be reflected in identical commits to that subdirectory of the outer repo (i.e. a commit to src/lib.rs
in the inner repo gets translated into a commit on submodule/src/lib.rs
in the outer repo), and for that submodule to not be a git repo anymore and go back to being a regular old subdirectory. That is, my desired end state is what I would have if I had done rm -rf .git
immediately after cloning the submodule's repo and continued my development from there.
I could do this by rolling the inner repo back to before I made the first change, moving the .git directory somewhere else, git add
ing that directory from the outer repo, moving the .git directory back, roll the inner repo forward one commit, rinse and repeat (I have a single digit number of commits in the inner repo, so that would theoretically be feasible), but I'm wondering if there's an easier way.