7

For the second time today git commit -m "don't quit me now" deletes my entire repo. So it goes:

$ git add .
$ git commit -m "please, be gentle"

[master 7af0e9c] please, be gentle
140 files changed, 0 insertions(+), 3186 deletions(-)
delete mode 100644 .DS_Store
delete mode 100644 .gitignore
delete mode 100644 .rspec
delete mode 100644 Gemfile
...

I've been using Github for Mac alongside the command line and wondering if that's somehow effing things up.

$ git checkout
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    .DS_Store
#   deleted:    .gitignore
#   deleted:    .rspec
#   deleted:    Gemfile
#   deleted:    Gemfile.lock
Jack Frost
  • 2,151
  • 3
  • 17
  • 21
  • 1
    What was the state of your repository (as obtained by `git status`) before you did the `git add .`? – Noufal Ibrahim Apr 11 '12 at 05:29
  • is your environment variable `GIT_DIR` or `GIT_WORK_TREE` set? – VonC Apr 11 '12 at 05:38
  • The previous instance of such a behavior wasn't very informative: http://stackoverflow.com/questions/6180151/git-commit-without-file-name-and-without-a . Does the problem persist if you clone your repo, try to make a modification there and a commit? – VonC Apr 11 '12 at 05:39
  • 1
    I hate to ask it but since you didn't mention it… the files are actually present on the disk when this is happening, right? – Andrew Marshall Apr 11 '12 at 05:40
  • What are you expecting git checkout to do? What has been you workflow since up to this point? – CB Bailey Apr 11 '12 at 05:47
  • @VonC I don't believe I've set my environment variable to either. I haven't tried cloning yet but will attempt it soon. @Andrew Marshall, yes, I the files are on disk. I'm attempting a real commit of files I've been working on. @Charles Bailey, I'm expecting `git checkout` to get my repo back to disk. My workflow to date has been straightforward: `git add .`, `git commit -m "all features are go!"`, `git push`, `git push heroku master`. I really haven't used Github for mac too extensively but mostly use it to review changes. – Jack Frost Apr 11 '12 at 05:55
  • @capncaveman: What do you mean by "get my repo back to disk"? – CB Bailey Apr 11 '12 at 06:56
  • @CharlesBailey my semantics are bad. I did `git push` despite imminent deletions. As expected, my github repo was rendered blank. I ran `git checkout` to get back to the previous commit. – Jack Frost Apr 11 '12 at 17:44
  • Did you pass parameters to git checkout? Otherwise why would it go back a commit? – CB Bailey Apr 12 '12 at 05:47

1 Answers1

5

Since git status tells you that everything is staged for deletion, before doing anything else, reset the index to HEAD:

git reset HEAD

After doing this, git status should echo

no changes added to commit (use "git add" and/or "git commit -a")

Then, try again:

git add .
git commit -m "new try"
eckes
  • 64,417
  • 29
  • 168
  • 201
  • 1
    Thanks, the repo's back to normal. However, I'm uncomfortable not knowing how it got into the crazy state in the first place. I'm the sole user on the repo and just using basic commands. – Jack Frost Apr 11 '12 at 15:45
  • The other thing about this fix is that it didn't go quite as described. `git status` actually indicated a bunch of files for deletion along with most of them being untracked. `git add .` put them back in the repo. Interestingly, I'm not seeing the last commit "new try" in the history. Weird stuff. – Jack Frost Apr 11 '12 at 15:51
  • This still isn't working. The `git commit` just cleared my repo again. Now I have a bunch of untracked folders and files that don't seem to be responding to `git add .`. – Jack Frost Apr 12 '12 at 03:35
  • this didn't work for me, same problem, i can git add . but git status will show clean tree so nothing to commit – Sergio Solorzano May 20 '21 at 08:32