Skip to content

Instantly share code, notes, and snippets.

@GrayedFox
Last active March 6, 2024 16:34
Show Gist options
  • Save GrayedFox/a191e201620bb4adce226dc11b947ae2 to your computer and use it in GitHub Desktop.
Save GrayedFox/a191e201620bb4adce226dc11b947ae2 to your computer and use it in GitHub Desktop.
Improved local patch management using named patch files, use carefully
#!/usr/bin/env bash
if [ $# -eq 1 ] ; then
NAME=$1
else
echo "Please pass exactly one argument, which is the name of the patch file"
exit 1
fi
git add .
# if previous patch file with the same name exists untrack it
if [ -f "$NAME.patch" ] ; then
git rm --cached $NAME.patch
fi
# warning: this will diff all changes into a file called NAME.patch and do a hard reset of the current branch
git diff --staged > $NAME.patch
git reset --hard $HEAD
@GrayedFox
Copy link
Author

add safety check to remove previous patch file if it exists

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