Read more

Git: undo delete

Daniel Straßner
May 23, 2017Software engineer at makandra GmbH

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

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

This restores the file status in the index:

git reset -- <file>

then check out a copy from the index

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 Show archive.org snapshot . Also be aware that it is not the same as a single dash, which is a shortcut for @{-1}(the last checked out branch) Show archive.org snapshot . This means you would checkout the file not from your current but the last branch you were on.

✗ git checkout - <file> # checks out <file> from previous branch
✔ git checkout -- <file>
Posted by Daniel Straßner to makandra dev (2017-05-23 13:37)