Clean the working directory (untracked files):
git clean -ffdx

Clean the working directory (tracked files):
git reset --hard @

Clean the working tree:
git rm -rf .

Find dangling/detached commits:
git log --pretty=format:'%h,%s' $(git rev-list -g --all)
Select/Checkout only files touched in the last commit (Bash):
git clean -ffdx
git reset --hard @
git rm -rf .
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT @ | tee changedfiles.txt
filename='changedfiles.txt'
n=1
while read line; do
echo "File No. $n: $line"
git checkout @ $line
n=$((n+1))
done < $filename
git rm -f changedfiles.txt


Back to Top