2011-10-19 49 views
1

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

帮助,如何重新获取我的文件?

编辑:这里是终端历史,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 [email protected]:dchhetri/Demo-s.git 
$ git push origin master 
error: src refspec master does not match any. 
error: failed to push some refs to '[email protected]:dchhetri/Demo-s.git' 
$ git remote add origin [email protected]: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 '[email protected]:dchhetri/Demo-s.git' 
$ git pull failed to push some refs to '[email protected]: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 '[email protected]:dchhetri/Demo-s.git' 
fatal: 'failed' does not appear to be a git repository 
fatal: The remote end hung up unexpectedly 
$ git pull [email protected]:dchhetri/Demo-s.git 
From github.com:dchhetri/Demo-s 
* branch   HEAD  -> FETCH_HEAD 
$ ls 
AStarDemo.jar 
+0

除了'git pull'外,你还运行过其他的命令吗? – ctcherry

+0

这就是我做的,git init,然后触摸README,然后git commit,然后git remote origin [email protected]:dchhetri/Demo-s.git,然后git push master,失败时说一些ref没有推到服务器,所以我做了一个git拉,我的文件都没有了。另外我想补充一点,以前我使用rm -r .git来从Foo的项目目录中删除.git文件夹,我不知道是否对Foo中的文件做了什么。 – dchhetri

+0

我添加了终端历史记录,它显示我之前的拉取请求,所有文件都在那里,现在它不是, – dchhetri

回答

3

我引用了记录您的终端会话中,似乎是有关以下的部分。这些是您的文件存在的位置和被单个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 [email protected]:dchhetri/Demo-s.git 

$ git pull [email protected]:dchhetri/Demo-s.git 
From github.com:dchhetri/Demo-s 
* branch   HEAD  -> FETCH_HEAD 

$ ls 
AStarDemo.jar 

(首先,说明你参与的情况下,你已经有了一个master分支在你的GitHub库中的该分支的最新版本只有一个文件,名为AStarDemo.jar。之前尝试推送失败的原因是您试图用本地分支覆盖master分支。通常,您只能将提交一个分支,如果你的提交包括该分支的历史记录除非你通过增加-f选项来“强制”推送,否则git不会让你这样做在你已经链接的长终端历史记录的其他点上,原因你推动fa的一些尝试在你创建任何提交之前,你正在尝试git push origin master - 你的本地master还不存在。)

在我引用的命令部分中,将stage中的所有文件与git add .),但不要继续提交它们。然后你似乎被git中的一个bug所击中 - 命令git pull <URL>,当在没有提交的存储库中执行时,似乎在没有警告的情况下清除了索引(暂存区)。这对我来说似乎是一个bug的原因是,如果您同样进行了暂停和未提交的更改,但您的确实指向了提交,那么git pull <URL>将会失败,并说这会丢失本地更改。在这种情况下,它似乎已经抛弃了你的舞台文件。 (我可以用git 1.7.5.4版来重现这一点。)

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

+0

感谢您的信息。不,我没有备份副本。我以为我现在已经失去了所有的希望,所以我准备从头开始。如果可能的话,我想把文件拿回来。我会尝试你今天提供的链接 – dchhetri

1

这不应该是原因。

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

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

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

+0

我没有使用git stash命令,虽然我确实使用了rm -r .git,这对我的Foo的项目会有什么影响吗?它不应该。我什至不能看到我的垃圾桶中的文件? – dchhetri

+0

历史存储在.git文件夹内。如果它消失了,并且你的文件也没有了,那么你无法恢复它们。也许你做了'rm -r'? – romaninsh

+0

我检查了我的终端历史记录,并在Foo的目录中找到了,rm .git -r是否是问题所在? – dchhetri

0

打以下命令撤消拉:

git reset --hard HEAD^ 
+0

当我试图执行它时,我得到这个错误,致命:ambiguous argument'HEAD ^':未知版本或路径不在工作树中。 使用' - '来分开修订版本的路径 – dchhetri

+0

我添加了终端历史记录,它显示我以前在拉请求之前,所有文件都在那里,现在在它之后,它不是 – dchhetri

+0

您得到此错误是因为您的存储库是不见了。 – ralphtheninja

相关问题