5

I have a project with some dependencies which are pulled as git submodules. I have for one of them a small patch to apply (about 6 line changes, nothing significant).

Is there a way to automatically apply this patch when pulling the submodule?

Paul92
  • 8,827
  • 1
  • 23
  • 37
  • 1
    Does this answer your question? [Is it possible to patch a submodule in Git from the parent project?](https://stackoverflow.com/questions/47562385/is-it-possible-to-patch-a-submodule-in-git-from-the-parent-project) – Fildor Mar 24 '20 at 12:47

1 Answers1

2

The git apply documentation states that:

If the patch contains any changes to submodules then git apply treats these changes as follows.

If --index is specified (explicitly or implicitly), then the submodule commits must match the index exactly for the patch to apply. If any of the submodules are checked-out, then these check-outs are completely ignored, i.e., they are not required to be up to date or clean and they are not updated.

If --index is not specified, then the submodule commits in the patch are ignored and only the absence or presence of the corresponding subdirectory is checked and (if possible) updated.

Hence, if you use git apply with the --index tag, I think you will be able to apply patches to submodules. Make sure to run a git submodule summary to check if there are any differences between what the superproject expects and what the submodule actually is. If there are any, do a git submodule update and you're all set!

Best.

torek
  • 448,244
  • 59
  • 642
  • 775
rasengan__
  • 883
  • 8
  • 16