I have a situation, a colleage of mine overwrote PHP files that I've made changes to , is it possible to roll back a file to a previous working version using the command line. No svn repositories are available and also not any backups.


I'm sorry to say that if you didn't make any backups, you're almost certainly SOL here, especially from the command line.

Unlinking (deleting) a file can sometimes leave the data recoverable as long as nothing else grabs that particular inode; editing a file overwrites the data.

If your colleague still has the editor he was working in open and its undo buffer is long enough, that might be a way to recover the original, but beyond that I'm afraid you're sunk. Sorry.

| improve this answer | |
  • Thanx for the response, busy setting up a SVN repository, just thought maybe maybe there's a chance of getting it back – Elitmiar Mar 10 '11 at 15:15
  • I usually just tarball my work and delete that tarball every once in a while. But I'd seriously consider git, hg, of svn to backup your code. You can even schedule it to commit every few hours with cron if you have to. – Blender Mar 10 '11 at 16:38
  • @Roland Consider using git, after some learning it's so easy to use and so fast, so you'll never think about not versioning anything (and you'll not understand how you ever could use svn). I need less than one minute to create a repo for a new project, to commit, and to clone to a server. Just my opinion, not gonna start a flame war. – maaartinus Mar 11 '11 at 10:39

Assuming you're using ext3, it might be possible to recover it if the replacement file was created as another inode (instead of overwriting the existing file), by using debugfs on the unmounted filesystem, and to find the inode of the original file. Unfortunately, if your colleage overwrite the file, rather than moving it aside and then deleting it, it's gone. I would suggest using debugfs with extreme caution, because you can seriously mess up a filesystem. It's use is only really for a last-ditch effort.

| improve this answer | |
  • @thanks, no unfortunately it wasn't created as a inode, thanks for the response. – Elitmiar Mar 10 '11 at 15:24

Usually you would have a tmp file created which begin with ~filename.extension. You can recover from that.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.