Recover deleted files with git

Asked

Viewed 1,284 times

1

I created a repository on github, gave my git init folder and after that I made the mistake of giving these two commands below, after that my files that were in my folder disappeared... how to get back the files ? i had not yet given any commit.

git add -A

git reset --hard


deivison@Desso MINGW64 /c/xampp/htdocs/adega (master)
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .editorconfig
        new file:   .gitignore
        new file:   .htaccess
        new file:   application/.htaccess
        new file:   application/cache/index.html
        new file:   application/config/autoload.php
        new file:   application/config/config.php
        new file:   application/config/constants.php
        new file:   application/config/database.php
        new file:   application/config/doctypes.php
        new file:   application/config/foreign_chars.php
        new file:   application/config/hooks.php
        new file:   application/config/index.html
        new file:   application/config/memcached.php
        new file:   application/config/migration.php
        new file:   application/config/mimes.php
        new file:   application/config/profiler.php
        new file:   application/config/routes.php
        new file:   application/config/smileys.php
        new file:   application/config/user_agents.php
        new file:   application/controllers/Cliente.php
        new file:   application/controllers/Entrada.php
        new file:   application/controllers/Movimentacao.php
        new file:   application/controllers/Produto.php
        new file:   application/controllers/Saida.php
        new file:   application/controllers/Template.php
        new file:   application/controllers/Venda.php
        new file:   application/controllers/index.html
        new file:   application/core/index.html
        new file:   application/helpers/index.html
        new file:   application/hooks/index.html
        new file:   application/index.html
        new file:   application/language/english/index.html
        new file:   application/language/index.html
        new file:   application/libraries/index.html
        new file:   application/logs/index.html
        new file:   application/models/M_Cliente.php
        new file:   application/models/M_Produto.php
        new file:   application/models/index.html
        new file:   application/third_party/index.html
        new file:   application/views/entrada.php




deivison@Desso MINGW64 /c/xampp/htdocs/adega (master)
$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'origin'

deivison@Desso MINGW64 /c/xampp/htdocs/adega (master)
$ git reset --hard
  • I recommend you read this basic guide(is in English), will familiarize you with the commands and basic operation of git.

  • See if you can restore with git checkout .. I do it every time I change something.

  • deivison@Desso MINGW64 /c/xampp/htdocs/adega (stock) $ git checkout . error: pathspec '.' Did not match any file(s) known to git. deivison@Desso MINGW64 /c/xampp/htdocs/cellar (stock) $ git checkout master error: pathspec 'master' Did not match any file(s) known to git. This is the error, and I can’t get back to the master branch

1 answer

1

Try to review in the log what happened to the command git log or if you prefer to use the command git log -p -2. This will display the history with diff of the last two changes or if you prefer to use this command to give a summary of the log:

git log --pretty=oneline

(remembering that this command will display summarized information on a line hash full and comment);

After this and checked try to recover with the commands: git checkout -- filename or if not git reset HEAD filename.

  • $ git log fatal: your Current branch 'stock' does not have any commits yet It gives this error because I didn’t commit this branch.. and I can’t get back to the master branch

  • @user120419 has tried git checkout HEAD nomedoarquivo? @Joaorobertoanjos , avoid posting two or more answers. Anything just click on edit and correct/supplement it.

Browser other questions tagged

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