gpt4 book ai didi

git - 为什么我所有的 git 存储库突然显示所有内容都已删除?

转载 作者:太空狗 更新时间:2023-10-29 13:53:24 26 4
gpt4 key购买 nike

文件在那里,git 只是告诉我它们已从存储库中删除。这可能是 Github 问题吗?

我已经导航到几天未处理的项目文件夹,并且像往常一样运行:

git status

但是,状态显示我的所有文件都已删除,而不是看到 1 或 2 个文件。然后,在“未跟踪文件”中,它显示了我在应用程序根目录中需要添加的所有文件和目录。

我不明白发生了什么,但我很担心自上次提交以来我所做的任何工作都消失了。

我用 git k 打开了 git log,在最上面我看到了:

Local changes checked in to index but not committed.

在我看到的正下方:

master    remotes/origins/master

注意:这个项目是针对github数据库的。

这是 git status 命令的输出:

➜  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/

最佳答案

这强烈建议您(或您间接调用的东西)删除或至少重命名 .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

在上面,我通过放回 index 文件来恢复,但如果它真的消失了,你可以使用 git reset< 从 HEAD 提交中重建它--mixed(默认)模式:

$ 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

[另外:您不需要 -- . 因为它们也是默认值。这更多是为了强调我们正在重置 . 中的每个路径,即 HEAD 提交中的路径。当然,我通过未明确指定 HEAD 来使用默认到 HEAD 的提交操作...]


1或者,也许您确实将环境变量 GIT_INDEX 设置为指向某个奇怪的地方。当GIT_INDEX 设置时,Git 使用.git/index,因此如果设置了它,将会覆盖默认值。

关于git - 为什么我所有的 git 存储库突然显示所有内容都已删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23189193/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com