Currently Available: Need a skilled Software Developer for your next project?
Categories
Git

Quickly Restore All Deleted Files in Git

If you’ve accidentally deleted multiple tracked files in your Git repository, you can bring them all back at once using this simple command:

git restore $(git status --porcelain | awk '/^ D/ {print $2}')

All deleted files will be restored to their previous state with a single command.


How It Works

  • git status --porcelain
    Outputs the status of your files in a simple, machine-friendly format (ideal for scripting).
  • awk '/^ D/ {print $2}'
    Filters the output to show only deleted files (D in the status column), and prints just the filenames.
  • git restore $(...)
    Restores all the deleted files listed from the previous command.

Similar Shortcuts

You can use similar patterns to quickly stage or restore other types of changes. For example, to stage all modified files (but not deleted/untracked):

git add $(git status --porcelain | awk '/^ M/ {print $2}')

Or, to restore all modified files (revert changes to tracked files):

git restore $(git status --porcelain | awk '/^ M/ {print $2}')
What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Subscribe to my newsletter

Get new posts when I publish them.

I respect your privacy. Unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *