Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git undo deleted files

I am new to git. I have checkout files from remote. I had to delete few files from the git repo. Instead of doing git rm command, I issued unix rm -rf folder command. I need to revert the delete command and then perform git rm command. How to revert to the latest code?

Note: I have not yet committed the staged files.The out out of git status is the list of files deleted in the below format:

#   deleted:    i18n/angular-locale_sl.js
#   deleted:    i18n/angular-locale_in.js 
like image 922
Pradeep Avatar asked Apr 28 '14 05:04

Pradeep


People also ask

How do I undo a deleted file in git?

If you're using the Tower Git client, you'll find the operations described above conveniently available in the GUI. Even better, in cases like committing a file deletion and then wanting to revert it, Tower's awesome undo feature lets you get the file back by simply pressing CMD-Z!

Can we restore deleted file in GitHub?

In the top right corner of GitHub.com, click your profile photo, then click Your organizations. Next to the organization, click Settings. In the left sidebar, click Deleted repositories. Next to the repository you want to restore, click Restore.

How do I Unstage deleted files?

Step 1. Go to the "Recycle Bin" location. Step 2. Find your accidentally deleted files or folders, select the file, and right-click on the "Restore" option to undo deleted files.

Does git show deleted files?

Listing all the deleted files in all of git history can be done by combining git log with --diff-filter . The log gives you lots of options to show different bits of information about the commit that happened at that point.


2 Answers

If you have staged the deletion, first unstage it:

git reset HEAD path/to/deleted/file

Then restore the file:

git checkout path/to/deleted/file
like image 139
Damien Bezborodow Avatar answered Oct 10 '22 18:10

Damien Bezborodow


Revert a git delete on your local machine

You're wanting to undo of git rm or rm followed by git add:

Restore the file in the index:

git reset -- <file>

after that check out from index

git checkout -- <file>

for example:

git reset -- src/main/java/de/foo/bar.java
git checkout -- src/main/java/de/foo/bar.java
like image 44
Sma Ma Avatar answered Oct 10 '22 17:10

Sma Ma