3

I added a subproject to a git repository by doing a subtree merge. I now need to apply a patch to the subproject, but running "git apply -v patch_name.patch" returns nothing. There's no error message and none of the files get changed either.

I've tried cloning the subproject separately (ie, into a subdirectory /tmp) and comparing that to what's in the subproject directory under the main project; the directories are the same.

When I run the patch against the clone under /tmp, it applies as expected. It seems that the problem is related to the fact that the subproject directory is the result of a subtree merge.

I guess I could patch the files under the fresh clone and then copy them over what's in the subproject directory under my main project. It seems like I shouldn't have to do that. Is there a better way around this?

Matt V.
  • 9,703
  • 10
  • 35
  • 56

1 Answers1

2

Quoting from the git apply manual:

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.

In other words, you must provide --index for git apply to pay attention to submodules.

If you want to "force through" the changes, you might consider using the normal patch command, although it won't get permissions changes and the like, or using a git checkout rev /path/to/dir on the subtree (or the manual copy you suggest).

Borealid
  • 95,191
  • 9
  • 106
  • 122