简体   繁体   中英

Why do ALL of my git repositories suddenly show that everything has been deleted?

The files are THERE, git just tells me that they have been deleted from the repository. Could this be a Github problem?

I have navigated to my project folder that I haven't worked on in a couple of days, and like usual I run:

git status

However, instead of seeing 1 or 2 files, the status shows that all of my files have been deleted. Then, in "Untracked Files", it shows all of my files and directories in app root that need to be added.

I don't understand what has happened, but I am very worried that any work I did since the last commit is gone.

I opened the git log up with git k , and at very the top I see:

Local changes checked in to index but not committed.

Right below that I see:

master    remotes/origins/master

Note: This project goes against a github database.

Here is the output from the git status command:

➜  mcp5_mobile git:(master) ✗ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

deleted:    .gitignore
deleted:    .rspec
deleted:    Gemfile
deleted:    README
deleted:    README.md
deleted:    Rakefile
deleted:    app/assets/images/MSDS_icon_rgb.jpg
deleted:    app/assets/images/MSDS_icon_rgb.png
deleted:    app/assets/images/addtocart.gif
<Continues to list every single file in the app. Over 1,100 files.>

Untracked files:
  (use "git add <file>..." to include in what will be committed)

.gitignore
.rspec
Gemfile
README
README.md
Rakefile
app/
autotest/
colorpicker.css
config.ru
config/
db/
deploy/
doc/
eye.js
features/
layout.css
lib/
public/
sample.xml
script/
spec/
termios/
test/
vendor/

This strongly suggests that you (or something you invoked indirectly) deleted or at least renamed .git/index : 1

$ ls
LICENSE.txt x.txt
$ git status
On branch master
nothing to commit, working directory clean
$ mv .git/index .git/xindex
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    LICENSE.txt
    deleted:    x.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    LICENSE.txt
    x.txt

$ mv .git/xindex .git/index
$ git status
On branch master
nothing to commit, working directory clean

In the above, I recovered by putting the index file back, but if it's really gone you can rebuild it from the HEAD commit using git reset 's --mixed (default) mode:

$ rm .git/index
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    LICENSE.txt
    deleted:    x.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    LICENSE.txt
    x.txt

$ git reset -- .
$ git status
On branch master
nothing to commit, working directory clean

[Aside: you don't need the -- . as those are also the default. This was more to emphasize that we're resetting every path inside . that is in the HEAD commit. Of course I'm using the default-to- HEAD -commit action by not specifying HEAD explicitly either...]


1 Alternatively, perhaps something you did set the environment variable GIT_INDEX to point somewhere odd. Git uses .git/index when GIT_INDEX is not set, so if something has set it, that would override the default.

A git repository is completely local. Therefore it is definitively not a github issue.

git status compares three different things. Your HEAD commit, your index and your working tree.

In your case it seems that the files are present it your working tree and your in your HEAD commit but where removed from your index.

A normal git diff compares your working tree with your HEAD commit. - If this diff looks fine you can simply do git add . to write the content of your working tree to your index. Alternatively you could use git reset to write the content of your HEAD commit to you index.

If you are generally worried about losing uncommitted changes, you should commit more often. Uncommitted changes are generally bad, because git does not know anything about them and therefore cannot help with restoring them in case of strange accidents.

Must have been a path issue. I was trying to install some gems the other day and had to do funny things with PATH, PKG_CONFIG_PATH, and C_INCLUDE_PATH to get some native libraries to compile. Anyway, I rebooted my Mac and now everything looks normal. I can't understand what it could be, I'm using the same git executable, I just checked. Are there some supporting libraries that git uses on startup that I may have messed up?

I will update the answer as soon as I get it figured out. If you know the answer, I will award it to you. Upvotes all around, I appreciate the rapid response of the SO community, this was a scary problem.

Same thing happened here (on a Mac/Yosemite). After laptop was in sleep mode all night, all of my local repositories showed all files deleted and in need of being added. Even repositories I had not worked in for months. I rebooted my machine and presto. Everything okay.

RD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM