Skip to content

Instantly share code, notes, and snippets.

@lossendae
Last active April 19, 2021 18:11
Show Gist options
  • Save lossendae/c97ac4f04c71a2d6dc49edaeebbb0af9 to your computer and use it in GitHub Desktop.
Save lossendae/c97ac4f04c71a2d6dc49edaeebbb0af9 to your computer and use it in GitHub Desktop.
Git reset status for file marked as changed but with no content modification (mostly due to file permission change)
#!/usr/bin/env bash
set -e
git status --porcelain | (
unset action
while read line; do
case "${line//[[:space:]]/}" in
'UU'*) action='check' ;;
'M'*) action='check' ;;
'D'*) action='ignore' ;;
'??'*) action='ignore' ;;
'A'*) action='ignore' ;;
'C'*) action='ignore' ;;
'R'*) action='ignore' ;;
esac
if [ "${action}" == "ignore" ]; then
echo " >> Ignoring : ${line}"
else
path=${line:2}
PATH_NO_WHITESPACE="$(echo -e "${path}" | tr -d '[:space:]')"
if git diff $PATH_NO_WHITESPACE | grep -B 2 @@ -q; then
echo " >> Ignoring file : $PATH_NO_WHITESPACE"
else
echo " << Checking out file : $PATH_NO_WHITESPACE"
git checkout $path
fi
fi
done
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment