After running some bash commands, some files were accidentally deleted. Doing git status
shows a mix of deleted and modified files, e.g.
deleted: folder/README.md
modified: folder/somescript.sh
If there is a long list of deleted files I don't want to manually git restore
each individually, and a git checkout .
would discard my yet to be stashed or committed changes. How do I restore only the deleted files leaving the modified files untouched?
Sharing my own quick hack in an answer, but better solutions are welcome. Thanks.
Combined the suggestions in the comments, to make a git alias:
git config --global alias.restore-deleted '!git restore $(git ls-files -d)'
Now I can just run git restore-deleted
to restore deleted files and leave the modified ones untouched.
This is what I put in my ~/.bashrc:
alias restoredeleted="git status | grep deleted | sed -e 's/deleted://' | xargs git restore"
Then I can conveniently run restoredeleted
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With