1

If I create a new branch and then delete files, can I get them back by checking out a previous commit?

for example:

git checkout -b get-rid-of-useless-files

rm useless.js

Oh no!

git checkout

phew(?)

2 Answers 2

3

Yes, if a file is already checked in and you delete it, you can get it back:

git checkout -- path/to/deleted/file
Sign up to request clarification or add additional context in comments.

Comments

2

To add to manojids answer, if you already git rm /path/to/deleted/file you can still git reset HEAD /path/to/deleted/file and then git checkout -- /path/to/deleted/file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.