Posted over 2 years ago. Visible to the public. Linked content.

Git: undo delete

Assuming you're wanting to undo the effects of git rm or rm followed by git add -A or something similar:

This restores the file status in the index:

Copy
git reset -- <file>

then check out a copy from the index

Copy
git checkout -- <file>

To undo git add , the first line above suffices, assuming you haven't committed yet.


Note:

Make sure to use double dashes -- to tell git to checkout a file instead of a branch. This only is relevant for files having the same name as a branch. Also be aware that it is not the same as a single dash, which is a shortcut for @{-1}(the last checked out branch). This means you would checkout the file not from your current but the last branch you were on.

Copy
✗ git checkout - <file> # checks out <file> from previous branch ✔ git checkout -- <file>

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Daniel Straßner
Last edit:
about 2 years ago
by Arne Hartherz
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Daniel Straßner to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more