Get back deleted files in Git

Asked

Viewed 1,837 times

5

Friends, good afternoon.

I removed some files inside the server, but I need them again, I have them in the git repository.

How do I redownload the repository files?

  • If you want to go back to the last commit, you can use git rebase HEAD

3 answers

3

Use $ git checkout chave where the keyword is the branch number at a stage where your files existed. Ex: $ git checkout bc39326028de55653c8245cb7077b44023239735 At that point you’ll see your files back. Copy those files out of your GIT-controlled folder and go back to the version you were before. Use again $ git checkout aChaveInicial. Pass the files you copied out of the directory to the desired position. Make a $ git add . and then commiserate $ git commit -m "arquivos de volta". There, your files are back and with the last versatile of your project.

To better visualize the dates and keys use the $gitk

2

Just reverse the commit you used to delete the files.

git revert <commit>

Where <commit> is the number of the commit you want to undo.

Documentation of Git Revert.

  • Thiago, I didn’t use any commit to delete the files. I just deleted it in place, I wanted to make it replace the repository for the location.

  • 1

    Have you tried a new Pull from the repository to your location?

2

I think I’d use that command:

 git reset --hard HEAD

Browser other questions tagged

You are not signed in. Login or sign up in order to post.