Create archive of modified files in GIT via batch file

前端 未结 1 1902
生来不讨喜
生来不讨喜 2020-12-18 04:07

I\'m using this git command to create an archive of the files modified within a specific commit:

git archive -o update.zip HEAD $(git diff --name-only COMMIT         


        
1条回答
  •  伪装坚强ぢ
    2020-12-18 04:43

    Assuming you need a windows batch file, and not a bash script, here is a minimal batch file that may do what you want:

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

    It works by collecting all lines of the output of the git diff ... command into an environment variable, and then using this to perform the git archive ... operation.

    Documentation for the Windows for command is here, including the /f switch. Documentation for the setlocal command is here.

    0 讨论(0)
提交回复
热议问题