2

From various sources I managed to modify a script I found to create an archive of the files that were added or changed between 2 changesets. The batch script is as follows:

setlocal enabledelayedexpansion
set output=
for /f "delims=" %%a in ('git diff --name-only %1 %2') do ( set output=!output! "%%a" )
git archive -o export.zip HEAD %output%
endlocal

This has worked great until today and all of a sudden I am getting the following error back:

The input line is too long. The syntax of the command is incorrect.

I've confirmed that the cause of this is the that result of %output% is too long but not sure if or how I can work around this?

ProNotion
  • 3,662
  • 3
  • 21
  • 30
  • Which various sources did you use to put your script together? –  Jun 27 '14 at 17:26
  • Not sure how it helps but here is one url http://pastebin.com/aZ19cEaD and here is another that I used to help http://git-scm.com/docs/git-archive. There were plenty of others I visited also before I got this to work. As a last resort I'm going to have a go at iterating each file and copying it to a folder if I can. – ProNotion Jun 27 '14 at 17:49

1 Answers1

2

If you wanted to export changed files between two commits, why not (instead on relying on DOS variable being set, and being potentially too long) do a:

git archive --output=file.zip HEAD $(git diff --name-only SHA1 SHA2)

Since it is an Unix syntax, you need to call the sh.exe included in Git for Windows (as I mention in "What is the exact meaning of Git Bash?")

The OP ProNotion proposes in the comments:

"C:\Program Files (x86)\Git\bin\sh.exe" --login -i -c "git archive -o export.zip HEAD $(git diff --name-only %1 %2)" 
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Because $(...) doesn't work in a windows command prompt - at least not for me. The result I get is ```error: unknown option `name-only'``` – ProNotion Jun 29 '14 at 09:02
  • @pro it will, in a git bash – VonC Jun 29 '14 at 09:03
  • But I don't think then this can be done via a batch file which is the intention as the process is to be automated? I will however explore the option further – ProNotion Jun 29 '14 at 09:08
  • What does work though is calling Bash from the batch file with the command you provided as follows: ```"C:\Program Files (x86)\Git\bin\sh.exe" --login -i -c "git archive -o export.zip HEAD $(git diff --name-only %1 %2)"``` – ProNotion Jun 29 '14 at 09:29
  • @ProNotion Looks good! I have included that command line in the answer for more visibility, as well as a link where I presented before the `sh.exe` included in Git for windows. – VonC Jun 29 '14 at 09:49
  • Finding this solution actually proves useful for a number of reasons aside from just my original question as it means I can stop fighting DOS restrictions and just make use of the Git Bash and use my DOS batch files to proxy the commands. – ProNotion Jun 30 '14 at 16:51
  • @ProNotion I agree: nice combination here! – VonC Jun 30 '14 at 16:52
  • seems like git archive command has problem if files are too many even with this method. – dev02 Sep 01 '17 at 17:44