Here we will be explaining how to recover deleted files in Git

 

Git Version

Below mentioned commands were executed in git version 2.20.1.windows.1

 

Assume that you had deleted two files Article.html and Accept.md and you haven’t committed yet, then executing git status would display the deleted files in red.

> git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
(use "git add/rm ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)

deleted: Accept.md
deleted: Article.html

no changes added to commit (use "git add" and/or "git commit -a")

 

Now executing the below command will display all the unstaged changes after RESET.

> git reset HEAD Article.html Accept.md
Unstaged changes after reset:
D Accept.md
D Article.html

 

You can now recover the deleted files using the below command:

git checkout -- Article.html Accept.md

 

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)