Skip to content

Instantly share code, notes, and snippets.

@ancho85
Last active August 23, 2019 15:37
Show Gist options
  • Save ancho85/a0c76acc4aff271f009dcfa4f9b8f86e to your computer and use it in GitHub Desktop.
Save ancho85/a0c76acc4aff271f009dcfa4f9b8f86e to your computer and use it in GitHub Desktop.
git patch generator by branchname. First parameter is full path where work was done, second is just the name of the generated patch before the branch name
@echo off
setlocal
for /f usebackq %%c in (`git -C %1 rev-parse --abbrev-ref HEAD `) do @set _branchname_="%%c"
for /f usebackq %%c in (`git -C %1 show-ref --heads -s master`) do @set _branchcommit_="%%c"
for /f usebackq %%c in (`git -C %1 merge-base master %_branchname_%`) do @set _mastercommit_="%%c"
IF "%_branchcommit_%"=="%_mastercommit_%" (
echo generating patch for %_branchname_%
git -C %1 diff --relative --no-prefix --no-textconv --ignore-submodules --abbrev master..%_branchname_% '*.py' '*.xml' > %1\%2-%_branchname_%.patch
) ELSE (
echo "first rebase master to branch %_branchname_% (CTRL+D in smartgit)"
echo "or merge it (CTRL+M in smartgit, best choice to keep tree history)"
echo "and then regenerate patch"
echo "branch commit %_branchcommit_%"
echo "master commit %_mastercommit_%"
exit 1
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment