Skip to content

Instantly share code, notes, and snippets.

@roma-glushko
Created June 23, 2020 18:29
Show Gist options
  • Save roma-glushko/6bb137790a7e6e24e66cbdda6bd38e2b to your computer and use it in GitHub Desktop.
Save roma-glushko/6bb137790a7e6e24e66cbdda6bd38e2b to your computer and use it in GitHub Desktop.
A simple interface around git commands that simplifies patch creation
#!/bin/bash
command=$1
path=$2
currentDir="`pwd`"
# display usage
# run commands one after the other using
[ $# -eq 0 ] && { echo -e "Usage: $0 command [path]"; exit 1; }
case $command in
"init"|"i")
echo "• Saving the current state of ${path} as initial..";
(cd $path && rm -rf .git);
( cd $path && git init && git add . && git commit -m "Patchy: Initial state of the directory" );;
"create"|"c"|"cr")
patchFile="${currentDir}/mypatch.patch"
echo "• Creating a new patch (${patchFile})";
( cd $path && git diff --binary > "${patchFile}" );;
"reset"|"r")
echo "• Reset all changes prior to the initial state..";
( cd $path && git reset --hard );;
"clean"|"cl")
echo "• Cleaning git repository under ${path}..";
( cd $path && rm -rf .git );;
*)
echo "Unknown command."
exit 2;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment