6

I am trying to apply multiple patches from one git repository to another. I've created the patches with (I want the 13 latest changes):

cd repoA
git format-patch -13 -o ..\patch-directory
cd ..\repoB
git am ..\patch-directory\*.patch

This gives:

fatal: could not open '..\patch-directory\*.patch' for reading: Invalid argument

A very similar question, seem to indicate this is the correct method (how to apply multiple git patches in one shot), yet it doesn't work. I can apply the patches individually, by passing the full filenames in multiple commands (and, I could easily create a script to apply them one-by-one), but, I'd like to know why this isn't working.

I am using git version 2.9.2.windows.1.

Community
  • 1
  • 1
MuertoExcobito
  • 9,741
  • 2
  • 37
  • 78
  • Did you try with an absolute path ? Have a look at this answer: http://stackoverflow.com/a/29888775/2531279 – Frodon Aug 15 '16 at 14:11
  • it doesn't work supplying an absolute path either, same error. – MuertoExcobito Aug 15 '16 at 14:24
  • Did you try the `format-patch` with the `--relative` argument ? – Frodon Aug 15 '16 at 15:36
  • Passing `--relative` to `format-patch` creates the exactly the same patches as without, and thus still doesn't work. – MuertoExcobito Aug 15 '16 at 15:54
  • I don't "do" Windows so I am not sure what the next step would be, but clearly the problem is that whatever you're using as a command-line interpreter is failing to expand `*.patch` into the various patches. – torek Aug 15 '16 at 17:55
  • 2
    I ran into the same error and was able to get it working using the Git bash that comes installed with git ([https://git-scm.com/downloads](https://git-scm.com/downloads)). – James Tupper Jan 05 '17 at 23:44

1 Answers1

7

If the shell you are using does not do whildcard expansion then you need to do this yourself or use a shell that does. The Windows shells do not so you can either use Git Bash or if you use Powershell then

git am (dir ..\patches\*.patch)

will do the expansion of the names and then pass all the expanded names as arguments to git am.

An alternative might be the foreach-object call (dir ..\patches\*.patch | ForEach-Object { git am $_}) but I would worry about this handling failed patches correctly.

patthoyts
  • 32,320
  • 3
  • 62
  • 93