I\'m working on a branch, say \"experimental\" branch which I branch out from my master branch.Then, I generate a user model in experimental branch, but does not add them to
While git clean
works well, I still find it useful to use my own script to clean the git repo, it has some advantages.
This shows a list of files to be cleaned, then interactively prompts to clean or not. This is nearly always what I want since interactively prompting per file gets tedious.
It also allows manual filtering of the list which comes in handy when there are file types you don't want to clean (and have reason not to commit).
git_clean.sh
#!/bin/bash
readarray -t -d '' FILES < <(
git ls-files -z --other --directory |
grep --null-data --null -v '.bin$\|Cargo.lock$'
)
if [ "$FILES" = "" ]; then
echo "Nothing to clean!"
exit 0
fi
echo "Dirty files:"
printf ' %s\n' "${FILES[@]}"
DO_REMOVE=0
while true; do
echo ""
read -p "Remove ${#FILES[@]} files? [y/n]: " choice
case "$choice" in
y|Y )
DO_REMOVE=1
break ;;
n|N )
echo "Exiting!"
break ;;
* ) echo "Invalid input, expected [Y/y/N/n]"
continue ;;
esac
done
if [ "$DO_REMOVE" -eq 1 ];then
echo "Removing!"
for f in "${FILES[@]}"; do
rm -rfv "$f"
done
fi