2012-04-28 59 views
5

我似乎已经失去了我的下午的工作在一个新的回购。以下是我所做的:舞台文件,然后远程添加,然后拉 - 我的文件不见了

  1. 在本地创建了一个新项目并完成了一些工作。
  2. 创建了一个回购GitHub上
  3. git init
  4. git add src
  5. git remote add origin [email protected]:Synesso/memx.git
  6. git pull origin master
  7. git add .gitignore
  8. git commit -m 'updated ignore'
  9. git push origin master

我的本地回购和github回购只有两个提交。最初的提交(由github在项目创建时作出)和第二次只包含文件.gitignore

在步骤4(git add src)中添加的文件不存在。他们似乎也没有上演。

当你做git pull时,你会丢失上演的文件吗?我可以以某种方式检索它们吗?

当前状态:

$ git status 
# On branch master 
nothing to commit (working directory clean) 

我inital add不在引用日志。

$ git reflog 
c80135d [email protected]{0}: checkout: moving from 999d128ea4e6969f9eacbceebb5f857f2aa5abb0 to master 
999d128 [email protected]{1}: checkout: moving from master to HEAD~1 
c80135d [email protected]{2}: checkout: moving from 999d128ea4e6969f9eacbceebb5f857f2aa5abb0 to master 
999d128 [email protected]{3}: checkout: moving from master to 999d128ea4e6969f9eacbceebb5f857f2aa5abb0 
c80135d [email protected]{4}: commit (amend): updated ignore 
28b4f90 [email protected]{5}: commit: updated ignore 
999d128 [email protected]{6}: initial pull 

history表明,我添加了src文件夹,但没有提交它:

223 git init 
225 git add src 
229 git add project/Build.scala 
234 git remote add origin [email protected]:Synesso/memx.git 
250 git pull origin master 

我知道,如果你尝试用本脏文件获取Git会抱怨。但是,这样做可以消除阶段性文件的拖动效果。这似乎是错误的。


我刚刚测试过这个过程,是的,它销毁了上演的文件。

[email protected]:~/projects$ mkdir x 
[email protected]:~/projects$ cd x 
[email protected]:~/projects/x$ git init 
Initialized empty Git repository in /home/jem/projects/x/.git/ 
[email protected]:~/projects/x$ echo "hi" > hello.world 
[email protected]:~/projects/x$ git add hello.world 
[email protected]:~/projects/x$ git status 
# On branch master 
# 
# Initial commit 
# 
# Changes to be committed: 
# (use "git rm --cached <file>..." to unstage) 
# 
#  new file: hello.world 
# 
[email protected]:~/projects/x$ ls -asl 
total 24 
4 drwxrwxr-x 3 jem jem 4096 Apr 28 20:56 . 
4 drwxr-xr-x 8 jem jem 4096 Apr 28 20:56 .. 
4 drwxrwxr-x 7 jem jem 4096 Apr 28 20:56 .git 
12 -rw-rw-r-- 1 jem jem 3 Apr 28 20:56 hello.world 
[email protected]:~/projects/x$ git remote add origin [email protected]:Synesso/memx.git 
[email protected]:~/projects/x$ git reflog 
fatal: bad default revision 'HEAD' 
[email protected]:~/projects/x$ git pull origin master 
remote: Counting objects: 7, done. 
remote: Compressing objects: 100% (5/5), done. 
remote: Total 7 (delta 0), reused 3 (delta 0) 
Unpacking objects: 100% (7/7), done. 
From github.com:Synesso/memx 
* branch   master  -> FETCH_HEAD 
[email protected]:~/projects/x$ ls -asl 
total 36 
4 drwxrwxr-x 3 jem jem 4096 Apr 28 20:53 . 
4 drwxr-xr-x 8 jem jem 4096 Apr 28 20:52 .. 
4 drwxrwxr-x 8 jem jem 4096 Apr 28 20:53 .git 
12 -rw-rw-r-- 1 jem jem 59 Apr 28 20:53 .gitignore 
12 -rw-rw-r-- 1 jem jem 9 Apr 28 20:53 README.md 
[email protected]:~/projects/x$ git reflog 
c80135d [email protected]{0}: initial pull 

文件hello.world被删除时未显示警告。

+1

'git reflog'会显示你的树形修改。但是如果你从未犯过'src'文件... – 2012-04-28 09:58:51

+0

现在'git status'说了什么? – vissi2 2012-04-28 10:40:54

回答

7

我能重现此不使用github上,使用两台主机(这里为hostB上,这是“远程”和玉簪,这是“本地”改名):

hostB$ cd /tmp; mkdir repo; cd repo; git init 
Initialized empty Git repository in /tmp/repo/.git/ 
hostB$ : > .gitignore; echo this is a readme > README.md 
hostB$ git add .; git commit -m initial 
[master (root-commit) 58d43bd] initial 
1 files changed, 1 insertions(+), 0 deletions(-) 
create mode 100644 .gitignore 
create mode 100644 README.md 

hostA$ cd /tmp; mkdir repo; cd repo; git init 
Initialized empty Git repository in /tmp/repo/.git/ 
hostA$ echo hi > hello.world 
hostA$ git add hello.world 
hostA$ git status 
# On branch master 
# 
# Initial commit 
# 
# Changes to be committed: 
# (use "git rm --cached <file>..." to unstage) 
# 
# new file: hello.world 
# 
hostA$ git remote add origin ssh://hostB.dom.ain/tmp/repo 
hostA$ git pull origin master 
remote: Counting objects: 4, done. 
remote: Compressing objects: 100% (2/2), done. 
remote: Total 4 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (4/4), done. 
From ssh://hostB.dom.ain/tmp/repo 
* branch   master  -> FETCH_HEAD 
hostA$ ls 
README.md 

重要:您可以使用git fsck --lost-found恢复您上演文件:

hostA$ git fsck --lost-found 
Checking object directories: 100% (256/256), done. 
dangling blob 45b983be36b73c0788dc9cbcb76cbb80fc7bb057 
hostA$ 

果然,如果检查BLOB(S)(现在在.git/lost-found/other恢复),这些将有你丢失的东西。 (任何目录结构会虽然走了,你必须弄清楚哪些文件是和重新把他们你想让他们。)

有趣的是,如果你git fetch origin其次git merge origin/master,它抓住了原点的初始修订(在这种情况下,使用来自hostB的.gitignore和README.md文件)并保留“要提交的更改”。赞成git fetch后跟git merge的另一个原因? :-)

+0

这是...美丽。谢谢。 – Synesso 2012-04-29 00:33:58

+0

我很感激 - 希望我能Flattr这个答案! – Treffynnon 2014-01-23 17:36:23

+0

@Treffynnon:2013年6月,它在“官方”git中被修复,并提交了'b4dc085a8dc2ec2fb5f6366fa672222b807ed655',并且包含在git v1.8.4中。 – torek 2014-01-23 17:51:46

0

您在github上的回购不包含任何有价值的文件。你忘了提交吗?

即使他们没有上演,你的src文件夹在哪里本地?如果你只是做了什么问题,git无论如何都无法吃掉你的文件。

+0

这就是我的想法。但src文件夹不再在本地存在。 – Synesso 2012-04-28 10:44:59

0

我想你应该提交本地更改后add之前remote addpull

  1. 的git的init
  2. 混帐添加SRC
  3. 混帐添加的.gitignore
  4. git的承诺-m '更新忽略'
  5. git remote add origin [email protected]:Synesso/memx.git
  6. git拉原点主
  7. 混帐推起源主
+0

我认为这很明显。 – Ashe 2012-04-28 23:00:37

1

我认为,这是一种具有新的存储库W/O单提交的不幸副作用。如果再次尝试测试,而是在本地执行:当你“拉”与“SRC”文件的工作目录,然后

git init; echo "Readme" > Readme; git add Readme; git commit -m 'Initial commit' 

,GIT会发出警告,更重要的是,不会删除的东西。

4

我收到了来自朱尼奥·哈默诺git的邮件列表如下答复:


这是一个意想不到的角落情况下干扰我们尝试过 高兴,事与愿违。

很长一段时间,没有历史,并要求拉被禁止,因为 “混帐拉”是大约是结合两个(或更多)的历史 一起拉动时,你有没有历史是无稽之谈---你只有 有一个历史(从另一侧的历史),没有什么 结合起来。

后来我们力求做到更好,为一些新用户时, 做“git的初始化”在一个空目录,然后是“混帐拉”,由 重新定义“合并”成没有历史意味着重置为触发的错误其他 历史。

这解决了“混帐初始化& &混帐拉”,但我们没有预料到的人 会做一个“混帐初始化& & git的添加& &混帐拉”序列,将有 不理智的结果不仅仅是其他错误。

一个只给出理智结果的补丁可能是这样的。

git-pull.sh | 3 +++ 
1 file changed, 3 insertions(+) 

diff --git a/git-pull.sh b/git-pull.sh 
index 2a10047..da102d0 100755 
--- a/git-pull.sh 
+++ b/git-pull.sh 
@@ -261,6 +261,9 @@ esac 

if test -z "$orig_head" 
then 
+  test $(git ls-files | wc -l) = 0 || 
+  die "$(gettext "Uncommitted changes in the index")" 
+ 
     git update-ref -m "initial pull" HEAD $merge_head "$curr_head" && 
     git read-tree -m -u HEAD || exit 1 
     exit 
+0

非常有趣。 +1 – VonC 2012-04-29 09:59:51

相关问题