Skip to content

Instantly share code, notes, and snippets.

@yngwie74
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yngwie74/b0cc3e1928f21d4e5ad5 to your computer and use it in GitHub Desktop.
Save yngwie74/b0cc3e1928f21d4e5ad5 to your computer and use it in GitHub Desktop.
Run a specific command for each file in the current repository with a given status
# usage: foreach "modified" "git restore"
# restores all the currently modified files, leaving others (deleted, renamed) alone
function foreach {
local status=$1
local action=$2
git status | awk '/'"$status"':/{print "'"$action"' \""$3"\""}' | bash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment