Skip to content

Instantly share code, notes, and snippets.

@jfairbank
Last active August 29, 2015 14:26
Show Gist options
  • Save jfairbank/e4ce5a0f1061d97afad5 to your computer and use it in GitHub Desktop.
Save jfairbank/e4ce5a0f1061d97afad5 to your computer and use it in GitHub Desktop.
git-diff-add
#!/bin/bash
# git diff a file and then be presented with the option to stage
# the file with "y" or stage a portion with patch via "p"
filepath="${1-.}"
git diff "$filepath"
[[ $? -ne 0 ]] && exit
printf "\nOk to stage? [y/p/N]: "
read stage
if [[ "$stage" == "y" || "$stage" == "Y" ]]; then
git add "$filepath"
elif [[ "$stage" == "p" || "$stage" == "P" ]]; then
git add -p "$filepath"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment