5
I have two folders (test-git1 and test-git2), in both I gave a clone of the server repository.
If I accidentally delete a file inside the test-git1 folder, how do I recover it? 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`
Until then ok, but how do I recover this data again? Do I have to give a clone again? There is a way to recover again by pull?
forehead
$ git reset --hard origin/master
, and notice that this will erase local changes you have made.– Sergio
You didn’t try to give a merge? When you give a
pull
you’re just bringing content from one repository to another but you’re not putting it in your workbook. But there are other ways to do what you want.– Maniero
now it’s weird, I deleted the test-git1 folder and cloned the server files again to a new folder with the same name (test-git1), now I went to try to add new files in this newly cloned folder and went to check in git status, no change/modification appeared, etc..
– João
very carefully with "reset --hard" git will remove all changes until it is in origin/master. Whenever you use this command be sure what you are doing. By the way, you are very sure!
– Flávio Granato
@Flavius reset only forces the local folder to have the same as the remote folder. I agree that it should be used with caution but does not change anything from
origin/master
– Sergio
"reset --hard" removes any and all files and changes that git knows and no possibility of recovery, it is not only force the local folder to have the same as the remote folder... I don’t know the level of knowledge of @João but it is always warn right... :-)
– Flávio Granato
my level of knowledge is: learning git since yesterday. what essential commands does a group of developers in a company use? git status, git pull, git checkout, git push, git add, git commit, and git log? have more tips?
– João
@John, even with his description, is easier if you give us the sequence of commands in each cloned repository, accompanied by the output on
git status
. It makes it easier to explain and help :).– Dherik