麻烦与混帐! 我不小心删除了我的项目文件?

我正在尝试这个git的东西,我想我搞砸了。 所以我在我的电脑里有一个名为Foo的项目。 我改变了目录到那个项目。 然后,git init,然后git commit到我的github中。 它说它没有推送一些ref到服务器,所以我搜索了它,有人说我需要先做一个git pull。 好的,所以我在Project Foo的目录中做了一个github服务器的git pull请求。 现在,我的项目Foo目录中的所有文件都被删除,只有来自git pull请求的文件存储在我的Project Foo的目录中。

帮助,我如何再次检索我的文件?

编辑:这里是终端的历史,http://codepad.org/cg9Gi7Ii - 文件消失点附近的日志命令是:

$ ls
Models      css     js      utils
README      index.html  styles
$ git init
Initialized empty Git repository in /Users/MacBoss/Documents/workspace/BlackboardCanvas/.git/
$ git add .
$ git remote add origin git@github.com:dchhetri/Demo-s.git
$ git push origin master
error: src refspec master does not match any.
error: failed to push some refs to 'git@github.com:dchhetri/Demo-s.git'
$ git remote add origin git@github.com:dchhetri/Demo-s.git
fatal: remote origin already exists.
$ git push origin master
error: src refspec master does not match any.
error: failed to push some refs to 'git@github.com:dchhetri/Demo-s.git'
$ git pull  failed to push some refs to 'git@github.com:dchhetri/Demo-s.git'
fatal: 'failed' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From github.com:dchhetri/Demo-s
 * [new branch]      master     -> origin/master
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:

    [branch "master"]
    remote = <nickname>
    merge = <remote-ref>

    [remote "<nickname>"]
    url = <url>
    fetch = <refspec>

See git-config(1) for details.
$ git pull  failed to push some refs to 'git@github.com:dchhetri/Demo-s.git'
fatal: 'failed' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
$ git pull git@github.com:dchhetri/Demo-s.git
From github.com:dchhetri/Demo-s
 * branch            HEAD       -> FETCH_HEAD
$ ls
AStarDemo.jar

我引用了您的终端会话的日志部分,这部分日志似乎与以下相关。 这些是你的文件存在的位置和被单个AStarDemo.jar替换的位置之间的AStarDemo.jar 。 我已经格式化,以便更清楚地发生了什么,并删除了失败的命令:

$ ls
Models      css     js      utils
README      index.html  styles

$ git init
Initialized empty Git repository in /Users/[...]/BlackboardCanvas/.git/

$ git add .

$ git remote add origin git@github.com:dchhetri/Demo-s.git

$ git pull git@github.com:dchhetri/Demo-s.git
From github.com:dchhetri/Demo-s
 * branch            HEAD       -> FETCH_HEAD

$ ls
AStarDemo.jar

(首先,为了解释您所处的情况,您的GitHub存储库中已经有一个master分支,该分支的最新版本中只有一个文件,称为AStarDemo.jar 。之前推送失败的是你试图用你的本地分支覆盖那个master分支,如果你的提交包含了分支的历史记录,你通常只能推送一个分支。除非你通过添加-f选项,git不会让你这样做,在你连接的长终端历史记录中的其他地方,你尝试推送失败的原因是你在尝试git push origin master之前创建任何提交 - 您的本地master尚不存在。)

在我引用的命令部分中,您将目录中的所有文件(使用git add . )进行git add .但不要继续提交它们。 那么你似乎被git中的一个bug所击中 - git pull <URL>命令在存储库中执行时没有提交,似乎在没有警告的情况下清除了索引(暂存区)。 这似乎是对我的一个错误的原因是,如果你有类似演出和未提交的更改,但你的HEAD 点提交时, git pull <URL>会失败,说这会失去你的本地修改。 在这种情况下,它似乎已经抛弃了你的舞台文件。 (我可以用git 1.7.5.4版来重现这一点。)

至于现在要做什么 - 你有另一个文件的副本吗? 如果你不这样做,而且你真的需要恢复它们,只要你还没有删除你的.git目录,那么你仍然可以这样做,尽管它有点工作。 (正如其他人在这里所评论的那样,通常你不应该删除包含整个项目历史的.git目录。)你可以在这里找到一些恢复这些阶段文件的指导:

  • 撤消git reset - 在暂存区域中使用未提交的文件

  • 这不应该是原因。

    考虑Git作为考试中的两名学生。 他们知道一些考试答案,偶尔看一眼寻找最近变化的其他工作,并对自己的工作应用相同的变化。

    当你从github“拉”时,它只会复制更改并应用它们。

    现在什么可能删除你的文件是“git藏匿”。 这会暂时隐藏您的更改,您可以使用“git stash list”来查看它们,或者使用“git stash pop”将它们还原。


    点击以下命令撤消拉:

    git reset --hard HEAD^
    
    链接地址: http://www.djcxy.com/p/4023.html

    上一篇: Trouble with git! I accidentally removed my project files?

    下一篇: How can I recover my commit after I did a git reset