Created
June 22, 2013 11:30
-
-
Save Sitebase/5840540 to your computer and use it in GitHub Desktop.
Bash function to get list of files that will be committed. Very handy when writing Git hooks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to get a list of files that will be committed by extension | |
# you can for example do "$(commit_files js css)" to get a list of js and css files that wil lbe commited | |
function commit_files() { | |
if [ $# -eq 0 ] ; then | |
echo $(git diff-index --name-only --diff-filter=ACM --cached HEAD --) | |
exit 0 | |
fi | |
extensions='' | |
for extension in "$@" | |
do | |
extensions="${extensions}(${extension})|" | |
done | |
regex="\.(${extensions%?})$" | |
echo $(git diff-index --name-only --diff-filter=ACM --cached HEAD -- | grep -P "$regex") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment