LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-04-2009, 03:42 PM   #1
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Accidantally deleted project with git rm, HOW TO GET IT BACK!


I wanted to use git rm, reorganize the files, and git add them back. But git rm ACTUALLY DELETED THE FILES FROM THE HARD DRIVE!!! How do I get them back and save them in a normal folder?
 
Old 12-04-2009, 04:09 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 13,807

Rep: Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365
Quote:
Originally Posted by MTK358 View Post
I wanted to use git rm, reorganize the files, and git add them back. But git rm ACTUALLY DELETED THE FILES FROM THE HARD DRIVE!!! How do I get them back and save them in a normal folder?
A quick Google for "recover delete files git" yielded:

Code:
To view deleted files use  git ls-files –deleted
To restore deted files just use git checkout – <deleted_file>
 
Old 12-04-2009, 04:13 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
So it's like this, right?

Code:
$ git checkout - <file1> <file2> ...
Do I need that "-" symbol?
 
Old 12-04-2009, 05:27 PM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
I tried "git checkout" with the SHA of the last good commit, but nothing.
 
Old 12-04-2009, 06:14 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,308

Rep: Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768
Quote:
Originally Posted by MTK358 View Post
So it's like this, right?

Code:
$ git checkout - <file1> <file2> ...
Do I need that "-" symbol?
It's actually a double dash "--", and it's only needed if one of the files starts with a dash so the filename won't be parsed as an option (doesn't hurt to put it in though).

If you do git status it tells what needs to be done in order to undo (aka "unstage"/"discard" in git-speak) or commit changes. I found git reset HEAD <file> was needed before git checkout <file>.

Last edited by ntubski; 12-04-2009 at 06:15 PM. Reason: s/on/an
 
Old 12-04-2009, 06:58 PM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
I'm kind of confused, could you just show me what to do to retrieve these files:

Code:
Application.h Application.cpp Widget.h Widget.cpp Container.h Container.cpp TopLevelWindow.h TopLevelWindow.cpp
I just really want to be certain because I don't want to lose them!
 
Old 12-05-2009, 08:14 AM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,308

Rep: Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768
Code:
~/tmp/files$ ls -A
Application.cpp  Container.cpp  .git                TopLevelWindow.h  Widget.h
Application.h    Container.h    TopLevelWindow.cpp  Widget.cpp
~/tmp/files$ git rm Application.h Application.cpp Widget.h Widget.cpp Container.h Container.cpp TopLevelWindow.h TopLevelWindow.cpp
rm 'Application.cpp'
rm 'Application.h'
rm 'Container.cpp'
rm 'Container.h'
rm 'TopLevelWindow.cpp'
rm 'TopLevelWindow.h'
rm 'Widget.cpp'
rm 'Widget.h'
~/tmp/files$ ls -A
.git
~/tmp/files$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       deleted:    Application.cpp
#       deleted:    Application.h
#       deleted:    Container.cpp
#       deleted:    Container.h
#       deleted:    TopLevelWindow.cpp
#       deleted:    TopLevelWindow.h
#       deleted:    Widget.cpp
#       deleted:    Widget.h
#
~/tmp/files$ git reset HEAD Application.h Application.cpp Widget.h Widget.cpp Container.h Container.cpp TopLevelWindow.h TopLevelWindow.cpp
Unstaged changes after reset:
M       Application.cpp
M       Application.h
M       Container.cpp
M       Container.h
M       TopLevelWindow.cpp
M       TopLevelWindow.h
M       Widget.cpp
M       Widget.h
~/tmp/files$ git status
# On branch master
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    Application.cpp
#       deleted:    Application.h
#       deleted:    Container.cpp
#       deleted:    Container.h
#       deleted:    TopLevelWindow.cpp
#       deleted:    TopLevelWindow.h
#       deleted:    Widget.cpp
#       deleted:    Widget.h
#
no changes added to commit (use "git add" and/or "git commit -a")
~/tmp/files$ git checkout -- Application.h Application.cpp Widget.h Widget.cpp Container.h Container.cpp TopLevelWindow.h TopLevelWindow.cpp
~/tmp/files$ git status
# On branch master
nothing to commit (working directory clean)
~/tmp/files$ ls -A
Application.cpp  Container.cpp  .git                TopLevelWindow.h  Widget.h
Application.h    Container.h    TopLevelWindow.cpp  Widget.cpp
 
1 members found this post helpful.
Old 12-05-2009, 08:45 AM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Thanks, I finally got my stuff back and can keep developing it.

I see that I really have to learn to use this good, because at my current understanding of git commands, a simple directory is safer.

But I still would like to know how to use it, because quite often I wish I could get a previous version of some file.

But I still can't find a simple enough tutorial anywhere, for example I would never have guessed from all the tutorials I have read that you have to add files if you modified them.

And (I think) that one of the most basic things you would want to do is to get a previous commit and get back to the most recent one, etc. but of all the tutorials that I read, none say how to do this!!!

Last edited by MTK358; 12-05-2009 at 08:49 AM.
 
Old 12-05-2009, 11:18 AM   #9
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,308

Rep: Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768
Quote:
Originally Posted by MTK358 View Post
But I still can't find a simple enough tutorial anywhere, for example I would never have guessed from all the tutorials I have read that you have to add files if you modified them.
Uh, did you read the Official git tutorial?

Quote:
Making changes

Modify some files, then add their updated contents to the index:

$ git add file1 file2 file3

You are now ready to commit.
Quote:
Originally Posted by MTK358 View Post
And (I think) that one of the most basic things you would want to do is to get a previous commit and get back to the most recent one, etc. but of all the tutorials that I read, none say how to do this!!!
Yeah, that is a bit more complicated because you end up creating a branch. See Git User's Manual (chapters 1-2). The short answer is git checkout HEAD^ for the previous revision and git checkout master to go back.
 
Old 12-05-2009, 01:40 PM   #10
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 59
In addition to the Git tutorial that Ntubski linked, Apress's Pro Git book is freely available online.

I highly recommend it: http://progit.org/book/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: GNOME desktop project migrates to Git LXer Syndicated Linux News 0 03-22-2009 06:50 PM
inconsistency issue of git-clone ***/git/mesa/drm with the existing kernel source centguy Linux - Desktop 2 10-08-2008 10:36 PM
I deleted some files and and want them back carlsonultimate Linux - Newbie 4 09-28-2007 06:28 PM
How to get the deleted contents back. UltraSoul Solaris / OpenSolaris 1 12-07-2006 01:08 AM
Deleted user, want him back... leupi Linux - Networking 5 01-17-2006 08:55 PM


All times are GMT -5. The time now is 10:58 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration