-1

I just initialized a repository by applying

git flow init
git remote add origin git@gitlab.com:folder/project.git
git add .

I noticed that I needed to comment on a folder, then used

git reset --hard

And tried to add the folder to .gitignore, but all folders that were untracked have been removed, after that I used

git clean -f -d

And now I have nothing, I lost my whole project and I don't know how to restore it.

Hawkins
  • 700
  • 6
  • 21
dcandamil
  • 111
  • 2
  • 12
  • Are you using any IDE, like Eclipse, Visual Studio or something? Maybe the IDE has some backup on Local History. See this: https://stackoverflow.com/questions/6267180/can-i-undo-a-git-clean-fdx – Pankwood Jun 22 '18 at 19:59
  • Thanks!, i see that not are solution, i deleted my own project – dcandamil Jun 22 '18 at 20:30
  • 1
    `reset` and `--hard` both sound dangerous... I always check documentation for this, still after years of using GIT – user85421 Jun 23 '18 at 15:52

1 Answers1

2

You're asking why all your project is gone, so let's break down the git commands you ran:

  1. git flow init is roughly equivalent to git init and committing an empty "Initial commit" with a develop branch forked from master.
  2. git remote add ... added your GitLab remote as a local remote so you can push/pull with it.
  3. git add . added everything in the local directory . to your staging area, where they're ready to be committed. All good so far!
  4. git reset --hard is where you ran into trouble. The git documentation shows that --hard resets the index and working tree, so any changes to tracked files are discarded. This means that everything you just added is reverted to their state in the last commit, an empty commit, so your files were deleted.
  5. git clean -f -d just forcefully removes untracked directories, of which I expect you had none after the hard reset.

In the future, I suggest reading the docs for git reset so you learn why it works that way with --hard. For the record, what you wanted to run here was probably just git reset without any arguments, which would have unstaged all of your staged changes, but not deleted any code. Then, your other commands (such as editing .gitignore) would have behaved like you expected.

Hawkins
  • 700
  • 6
  • 21
  • 1
    Also committing or stashing untracked code, even if the code is temporary, will help undo removals caused by a reset. – evolutionxbox Jun 23 '18 at 12:54