alexrezit
V2EX  ›  iDev

今天一个下午写的豆瓣登录框架, 自己手贱一个 git pull 就给搞没了.

By alexrezit at 2013 年 1 月 16 日 · 14188 次点击
39 条回复  •  2018-01-21 17:08:46 +08:00
run2
   1
run2  
   2013 年 1 月 16 日
难道一次都木有commit过-,-
dongsheng
   2
dongsheng  
   2013 年 1 月 16 日
git pull怎么会覆盖本地数据?如果你之前有commit的话,可以用git reflog找到hash code,然后cherrypick回来
alexrezit
   3
alexrezit  
OP
   2013 年 1 月 16 日
@sobigfish
是的... 本来只想写个测试一下, 后来发现写得还不错, 想丢到 github 上分享给基友们, 结果...
madao
   4
madao  
   2013 年 1 月 16 日
。。。pull前一般都得gca吧
@alexrezit
BOYPT
   5
BOYPT  
   2013 年 1 月 16 日
pull怎么可能覆盖代码,你本地没提交根本不可能pull的回来。
BOYPT
   6
BOYPT  
   2013 年 1 月 16 日
除非你reset hard了。
swulling
   7
swulling  
   2013 年 1 月 16 日
ls说的对啊
1. 你本地commit了,那无论如何都能用reflog找回来
2. 你本地没有commit,那根本就pull不成功啊
alexrezit
   8
alexrezit  
OP
   2013 年 1 月 16 日
@BOYPT
@swulling
不知道什么情况... = = 就是 pull 成功了, 原来的目录都在, 文件消失了...
swulling
   9
swulling  
   2013 年 1 月 16 日   ❤️ 1
@alexrezit 你commit了么?
alexrezit
   10
alexrezit  
OP
   2013 年 1 月 16 日
@swulling 木有...
remaerd
   11
remaerd  
   2013 年 1 月 16 日
我之前也经常出现跟 LZ 一样的情况.... 杯具死了。
chloerei
   12
chloerei  
   2013 年 1 月 16 日   ❤️ 1
没有 add 的文件,不会被覆盖。

add 了文件没有 commit,不能 pull。

commit 了之后 pull 有冲突,会自行解决或者提示需要编辑。

只要 commit 过,都可以用 git reflog 找回。

楼主可以贴下命令行 history,看看进行过什么操作。
Auston_Jary
   13
Auston_Jary  
   2013 年 1 月 17 日
这有点不科学。。。
alexrezit
   14
alexrezit  
OP
   2013 年 1 月 17 日
@Auston_Jary
我也觉得..
BOYPT
   15
BOYPT  
   2013 年 1 月 17 日
@alexrezit 那估计是你没保存了。
BB9z
   16
BB9z  
   2013 年 1 月 17 日
Time Machine。救过不下5次命了,全跟git操作不当有关。
alexrezit
   17
alexrezit  
OP
   2013 年 1 月 17 日
@BB9z 在家一直用 TM, 在外面总是忘了插... orz
neo1989
   18
neo1989  
   2013 年 1 月 17 日
pull怎么会覆盖? 莫非楼猪checkout了。
xatest
   19
xatest  
   2013 年 1 月 17 日
跟pull没关系,一定是其他操作导致的~
mrhooray
   20
mrhooray  
   2013 年 1 月 17 日
楼主贴一下git log上?就知道到底怎么样拉
mrhooray
   21
mrhooray  
   2013 年 1 月 17 日
@mrhooray 楼主贴一下git log上来?
alexrezit
   22
alexrezit  
OP
   2013 年 1 月 17 日
@neo1989
@xatest
@mrhooray

g init
g add *
g rm -r --cached RSocialDemo.xcodeproj/xcuserdata/
g remote add origin [email protected]:AlexRezit/RSocialDemo.git
gpl
gps
l
lr

就是这样...
g="git"
gpl="git pull"
gps="git push"
l="ls -FG"
lr="ls -FGR"
chenha0
   23
chenha0  
   2013 年 1 月 17 日
自从用了zsh在命令行提示符里提示有未提交代码就没发生过这种悲剧。。
chloerei
   24
chloerei  
   2013 年 1 月 17 日
我重现一遍,到 git pull 的时候应该会出现

There is no tracking information for the current branch.
Please specify which branch you want to merge with.

数据没丢。

但是指定分支之后 git pull origin master,pull 成功,数据丢了。

后来再测试,先 commit 一次,再修改再 pull,pull 失败,数据还在。

看来真的是 init 之后 add 了不 commit,然后 pull,add 的数据会丢。
chloerei
   25
chloerei  
   2013 年 1 月 17 日
我的习惯是进行任何操作前都 git status,确保 working directory clean 才进行操作。
alexrezit
   26
alexrezit  
OP
   2013 年 1 月 17 日
@chloerei
我手太快了... orz
swulling
   27
swulling  
   2013 年 1 月 17 日   ❤️ 2
@alexrezit
@chloerei

其实是能找回来的,我测试了下

在你git pull origin master后,看起来你原来在stage区域的文件是丢了。但其实没有


$ git fsck --lost-found
Checking object directories: 100% (256/256), done.
Checking objects: 100% (748/748), done.
dangling blob 61780798228d17af2d34fce4cfbdf35556832472
dangling blob 78981922613b2afb6025042ff6bd878ac1994e85
dangling blob f2ad6c76f0115a6ba5b00456a849810e7ec0af20

然后去.git/lost-found/other就能找到这些blob
swulling
   28
swulling  
   2013 年 1 月 17 日
@alexrezit
@chloerei
唯一的缺点就是目录结构和文件名都没了,不过相信也是一大帮助吧。。。

另外编辑器的自动保存功能也很重要,我的VIM常年打开 backup , so。。。
swulling
   29
swulling  
   2013 年 1 月 17 日
再补充一下,git add 空文件是找不回来,只能找回文件的内容。。
qiukun
   30
qiukun  
   2013 年 1 月 17 日
开学也遇到 git 用不好的状况。就没有 lightweight 点的吗?我不用 branch 神马的,我只要恢复
swulling
   31
swulling  
   2013 年 1 月 17 日
@qiukun Dropbox,支持History version
alexrezit
   32
alexrezit  
OP
   2013 年 1 月 17 日
@swulling
Thx. 不过我已经重写完了.
btw 怎么使用 vim 的 backup 功能?


@qiukun
你是神马专业的啊?
还是好好学 git 吧, 这个无所谓轻量不轻量的.
swulling
   33
swulling  
   2013 年 1 月 17 日   ❤️ 1
@alexrezit 我的vim config

"" 备份/Backups
set undodir=~/.vim/tmp/undo// " undo files
set backupdir=~/.vim/tmp/backup// " backups
set directory=~/.vim/tmp/swap// " swap files
set backup " enable backups

有一次不小心把编辑了很久的文件直接rm了,但是在backupdir中找回来了。。而且就连swap文件都会backup
qiukun
   34
qiukun  
   2013 年 1 月 17 日
@alexrezit 计算机科学与技术,嗯,下个 project 好好学 git
@swulling 0 0 那下次扔硬币决定用哪个
alexrezit
   35
alexrezit  
OP
   2013 年 1 月 17 日
@swulling
Thanks. 已加入我的 vimrc.

@qiukun
原来是妓院的... 如果你真的是大一的话, 应该还在宏福吧? 和我们软院的苦逼同学们在一个校区... = =
sutar
   36
sutar  
   2013 年 1 月 17 日
@qiukun hg也可以考虑
alexrezit
   37
alexrezit  
OP
   2013 年 1 月 17 日
@sutar
hg 不如 git.
wgziOS
   38
wgziOS  
   2017 年 6 月 1 日
@swulling 说的对
YIFEIO
   39
YIFEIO  
   2018 年 1 月 21 日
杯具。。。我写了一周的代码没了,幸亏只是用来学习的一个小项目
iOS 开发实用技术导航
NSHipster 中文版
› http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
› http://www.cocos2d-iphone.org/
CocoaPods
› http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
› http://code.google.com/mobile/analytics/
WWDC
› https://developer.apple.com/wwdc/
Design Guides and Resources
› https://developer.apple.com/design/
Transcripts of WWDC sessions
› http://asciiwwdc.com
Cocoa with Love
› http://cocoawithlove.com/
Cocoa Dev Central
› http://cocoadevcentral.com/
NSHipster
› http://nshipster.com/
Style Guides
› Google Objective-C Style Guide
› NYTimes Objective-C Style Guide
Useful Tools and Services
› Charles Web Debugging Proxy
› Smore
© 2026 V2EX · 99ms · 3.9.8.5