Recover a file in GIT

4

I have two folders (test-git1 and test-git2), in both I gave a clone of the server repository.

If I delete an unintentional file inside the git1-test folder, how do I get it back? I tried to give git pull origin master , but this message appears:

$ git pull origin master
From github.com:asdasdadasasd/teste-git
 * branch            master     -> FETCH_HEAD
Already up-to-date.

In my test-git1 folder, I delete the file joao.txt , then I made a

git status
'deleted:    joao.txt'

So long, okay, but how do I get this data back? Do I have to give a clone again? Is there a way to retrieve the pull again?

    
asked by anonymous 10.04.2015 / 20:45

3 answers

3

Since you cloned the repository and soon after that deleted the file (the status deleted you said), to recover it just run:

git checkout <nome do arquivo excluído>

This command discards all modifications made to the file passed as a parameter since the last commit (version registration). But the checkout command is more powerful than this, it accepts several other options: git-checkout docs

    
11.04.2015 / 13:08
1

You can use these commands:

git rev-list -n 1 HEAD -- <file_path>

Where -n X is the number of previous commits the file exists.

git checkout <deleting_commit>^ -- <file_path>

This command is to pull the file again.

Here has the same problem.

    
10.04.2015 / 20:54
0

I answered that here : My answer is worth cases where you just used it:

git checkout -- .

Before you commit something.

    
02.09.2016 / 17:35