Search code examples
gitgit-submodulespull-requestgit-fork

Merge pull request without submodules?


I have a git repository "R", which used to have a lot of submodules.

Now several things happend in this order:

  1. Person "P" created a fork "F" of the repository and made some changes to it.

  2. In the meantime, the submodules were removed in repository R.

  3. P creates a pull request for F, to merge their changes into R. F still has the submodules, while R does not.

If I were to just merge the changes, it would re-add the submodules to the repository, which I then would have to remove again. I.e. in the git history, submodules would be removed, then added again and then removed again. I could see this causing a lot of problems if someone tried to pull the latest changes. If possible, I would like to merge the changes without the submodules being re-added in the history.

What would be the best way of handling this? My idea currently is this:

  1. Merge F into a new branch B
  2. Rebase and Merge B to the main branch M

Would that work, or would that still cause the submodules to be re-added if someone pulls the changes?


Solution

  • Your assumption

    If I were to just merge the changes, it would re-add the submodules ...

    is not correct. Two cases are possible:

    • F did not change the submodule. In this case git merge will keep the deletion of the submodule.
    • F did change something in the submodule so it is now included with a different commit. In this case git merge will throw a conflict and you would have to resolve it: Keep the submodule deleted or use the new version from F.

    Regarding your idea you need to make sure you create the branch B at a commit where the submodule was not yet deleted. Ideally you would use the commit that F based his branch on.