Skip to content

Instantly share code, notes, and snippets.

@Taosif7
Last active February 7, 2022 08:42
Show Gist options
  • Save Taosif7/85f42ea81d893416672830872a8906e8 to your computer and use it in GitHub Desktop.
Save Taosif7/85f42ea81d893416672830872a8906e8 to your computer and use it in GitHub Desktop.
A batch script that zips the changed files from provided commit with folder stucture
@echo off
setlocal EnableDelayedExpansion
REM ## Remove diff file if exists
if exist diff-filelist.txt del /f diff-filelist.txt
REM ## set output file name
set "outputFileName=%2"
IF "%~2" == "" ( SET "outputFileName=output.zip" )
echo Zipping difference files from commits above %1 to %outputFileName%
REM ## Get file names
git diff --name-only %1 HEAD > diff-filelist.txt
REM Initialize the output file var
set "files="
REM Catenate all files name lines that exists, in the same variable separated by " "
for /F "delims=" %%a in (diff-filelist.txt) do (
IF exist "%%a" set "files=%%a !files!"
)
REM ## Make zip
tar.exe -a -c -f %outputFileName% %files%
REM ## Cleanup
del /f diff-filelist.txt
pause
@Taosif7
Copy link
Author

Taosif7 commented Feb 7, 2022

Usage:

Put in a folder whose path is accessible to your system, like windows/system32
Then run:

git-diff-zip HASH_OF_COMMIT_ABOVE_WHICH_DIFF_FILES_TO_BE_ZIPPED [output-file-name.zip]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment