如何恢复unstaged的文件?

77 views
Skip to first unread message

AleiPhoenix

unread,
May 13, 2011, 2:37:15 AM5/13/11
to Git中文用户组, liu...@anjuke.com
Hi, all
有个同事刚刚在checkout其他branch的时候忘记把文件commit掉了,导致文件丢失。
网上找了一下有几种恢复方案。

git ls-files -d
这个似乎一定是要add过的文件。这个方法在现有情况下不行。

git fsck --lost-found
ls .git/lost-found/other 这里似乎是那些unstage的文件,能找到,但不清楚是否完整。(已经比没有强了)
ls .git/lost-found/commit 这里应该是那些commit的记录

于是请问一下大家有没遇到过这种情况,如何恢复呢?

Thanks!

闲耘(tm)

unread,
May 15, 2011, 7:41:07 PM5/15/11
to git...@googlegroups.com
完全没有通过 git add 加入到版本控制么?
估计是恢复不了了。

我记得 co 的时候,如果有这种文件会提示的啊。

--
闲耘™ (@hotoo, hotoo.me)




2011/5/13 AleiPhoenix <aleip...@gmail.com>

aleip...@gmail.com

unread,
May 15, 2011, 9:05:01 PM5/15/11
to git...@googlegroups.com
刚才看了一下,似乎是没提示的。
mkdir /tmp/git
cd /tmp/git
git init
touch hello
git add -A
git ci -m "init"
git br test
git co test
touch hello2

这时候git co master 是没有任何提示的

如果git add -A把hello2 add进来再git co master
会有提示:
[aleiphoenix@arch:git$] [test] git co master
A    hello2

某也记得以前有过一次未staged或者未提交是会警告并没有checkout的。

2011/5/16 闲耘(tm) <hotoo.cn@gmail.com>



--
This mail is sent using Gmail web.

Contact:
twitter: AReverie

Peter

unread,
May 15, 2011, 9:08:25 PM5/15/11
to git...@googlegroups.com
从原理上说,如果没有stage(git add) 过,Git是不会保存的

如果对于git工作目录里的每个文件都要管理的话,工作量确实很大。




--
liuhui998 blog http://liuhui998.com
twitter http://twitter.com/liuhui998

aleip...@gmail.com

unread,
May 15, 2011, 9:36:34 PM5/15/11
to git...@googlegroups.com
Thanks!

可能他原来add过了。

总之这是操作规范上的问题,实在不能归咎于git
:)

2011/5/16 Peter <liuh...@gmail.com>
Reply all
Reply to author
Forward
0 new messages