Paul92
Paul92

Reputation: 9082

Git patch submodule

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?

Upvotes: 6

Views: 2372

Answers (1)

rasengan__
rasengan__

Reputation: 987

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.

Upvotes: 2

Related Questions