git - Restore deleted files from commit -


i've done following series of steps , don't know how recover files.

  1. git add file.txt
  2. git commit -m "message"
  3. rm file.txt
  4. git commit -am "message"

ideally should have pushed changes after step 2 , delete forgot. there way recover file?

many thanks!

you can recover file previous revision checkout command:

git checkout head^ file.txt 

or, if haven't pushed commit yet, might rather want reset commit instead:

git reset --hard head^ 

this reset working tree same state of previous commit. changes after previous commit gone.

if don't want changes gone, undo act of commit itself, can reset without --hard option, , restore deleted file with:

git reset head^ git checkout file.txt 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -