Undelete The Deleted Command in Bash

undelete the deleted command in bash

To undo, use either

  • Ctrl+X, Ctrl+U; or
  • Ctrl+_ (underscore).

See bind -P for a full list of keybindings in bash.

git recover deleted file where no commit was made after the delete

The output tells you what you need to do. git reset HEAD cc.properties etc.

This will unstage the rm operation. After that, running a git status again will tell you that you need to do a git checkout -- cc.properties to get the file back.

Update:
I have this in my config file

$ git config alias.unstage
reset HEAD

which I usually use to unstage stuff.

How to list recently deleted files from a directory?

You can use the debugfs utility,

debugfs is a simple to use RAM-based file system specially designed
for debugging purposes

First, run debugfs /dev/hda13 in your terminal (replacing /dev/hda13 with your own disk/partition).

(NOTE: You can find the name of your disk by running df / in the terminal).

Once in debug mode, you can use the command lsdel to list inodes corresponding with deleted files.

When files are removed in linux they are only un-linked but their
inodes (addresses in the disk where the file is actually present) are
not removed

To get paths of these deleted files you can use debugfs -R "ncheck 320236" replacing the number with your particular inode.

Inode   Pathname
320236 /path/to/file

From here you can also inspect the contents of deleted files with cat. (NOTE: You can also recover from here if necessary).

Great post about this here.

Can I recover a branch after its deletion in Git?

Yes, you should be able to do git reflog --no-abbrev and find the SHA1 for the commit at the tip of your deleted branch, then just git checkout [sha]. And once you're at that commit, you can just git checkout -b [branchname] to recreate the branch from there.


Credit to @Cascabel for this condensed/one-liner version and @Snowcrash for how to obtain the sha.

If you've just deleted the branch you'll see something like this in your terminal Deleted branch <your-branch> (was <sha>). Then just use that <sha> in this one-liner:

git checkout -b <your-branch> <sha>

Is it possible to somehow undo the results of the mv command?

No. Not easily. Sorry.

Restoring from backup would be the best option.

See the answers to the question "Recovering accidentally deleted files" over at Unix & Linux, if you feel like doing a bit of low-level file access.

How do I find and restore a deleted file in a Git repository?

Find the last commit that affected the given path. As the file isn't in the HEAD commit, that previous commit must have deleted it.

git rev-list -n 1 HEAD -- <file_path>

Then checkout the version at the commit before, using the caret (^) symbol:

git checkout <deleting_commit>^ -- <file_path>

Or in one command, if $file is the file in question.

git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"

If you are using zsh and have the EXTENDED_GLOB option enabled, the caret symbol won't work. You can use ~1 instead.

git checkout $(git rev-list -n 1 HEAD -- "$file")~1 -- "$file"


Related Topics



Leave a reply



Submit