V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
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
alexrezit
V2EX  ›  iDev

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

  •  
  •   alexrezit · 2013-01-16 21:45:06 +08:00 · 12628 次点击
    这是一个创建于 4116 天前的主题,其中的信息可能已经有所发展或是发生改变。
    39 条回复    2018-01-21 17:08:46 +08:00
    sobigfish
        1
    sobigfish  
       2013-01-16 21:52:55 +08:00
    难道一次都木有commit过-,-
    dongsheng
        2
    dongsheng  
       2013-01-16 21:55:09 +08:00
    git pull怎么会覆盖本地数据?如果你之前有commit的话,可以用git reflog找到hash code,然后cherrypick回来
    alexrezit
        3
    alexrezit  
    OP
       2013-01-16 21:57:22 +08:00
    @sobigfish
    是的... 本来只想写个测试一下, 后来发现写得还不错, 想丢到 github 上分享给基友们, 结果...
    madao
        4
    madao  
       2013-01-16 22:11:53 +08:00
    。。。pull前一般都得gca吧
    @alexrezit
    BOYPT
        5
    BOYPT  
       2013-01-16 22:19:13 +08:00
    pull怎么可能覆盖代码,你本地没提交根本不可能pull的回来。
    BOYPT
        6
    BOYPT  
       2013-01-16 22:19:56 +08:00
    除非你reset hard了。
    swulling
        7
    swulling  
       2013-01-16 22:35:37 +08:00
    ls说的对啊
    1. 你本地commit了,那无论如何都能用reflog找回来
    2. 你本地没有commit,那根本就pull不成功啊
    alexrezit
        8
    alexrezit  
    OP
       2013-01-16 23:19:43 +08:00
    @BOYPT
    @swulling
    不知道什么情况... = = 就是 pull 成功了, 原来的目录都在, 文件消失了...
    swulling
        9
    swulling  
       2013-01-16 23:21:53 +08:00   ❤️ 1
    @alexrezit 你commit了么?
    alexrezit
        10
    alexrezit  
    OP
       2013-01-16 23:23:20 +08:00
    @swulling 木有...
    remaerd
        11
    remaerd  
       2013-01-16 23:28:37 +08:00
    我之前也经常出现跟 LZ 一样的情况.... 杯具死了。
    chloerei
        12
    chloerei  
       2013-01-16 23:37:23 +08:00   ❤️ 1
    没有 add 的文件,不会被覆盖。

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

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

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

    楼主可以贴下命令行 history,看看进行过什么操作。
    Auston_Jary
        13
    Auston_Jary  
       2013-01-17 00:17:03 +08:00
    这有点不科学。。。
    alexrezit
        14
    alexrezit  
    OP
       2013-01-17 01:17:41 +08:00
    @Auston_Jary
    我也觉得..
    BOYPT
        15
    BOYPT  
       2013-01-17 08:58:45 +08:00
    @alexrezit 那估计是你没保存了。
    BB9z
        16
    BB9z  
       2013-01-17 09:06:54 +08:00
    Time Machine。救过不下5次命了,全跟git操作不当有关。
    alexrezit
        17
    alexrezit  
    OP
       2013-01-17 09:09:05 +08:00
    @BB9z 在家一直用 TM, 在外面总是忘了插... orz
    neo1989
        18
    neo1989  
       2013-01-17 09:37:19 +08:00
    pull怎么会覆盖? 莫非楼猪checkout了。
    xatest
        19
    xatest  
       2013-01-17 09:53:15 +08:00
    跟pull没关系,一定是其他操作导致的~
    mrhooray
        20
    mrhooray  
       2013-01-17 10:27:49 +08:00
    楼主贴一下git log上?就知道到底怎么样拉
    mrhooray
        21
    mrhooray  
       2013-01-17 10:28:24 +08:00
    @mrhooray 楼主贴一下git log上来?
    alexrezit
        22
    alexrezit  
    OP
       2013-01-17 11:23:18 +08:00
    @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-01-17 11:29:05 +08:00
    自从用了zsh在命令行提示符里提示有未提交代码就没发生过这种悲剧。。
    chloerei
        24
    chloerei  
       2013-01-17 11:44:41 +08:00
    我重现一遍,到 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-01-17 11:47:13 +08:00
    我的习惯是进行任何操作前都 git status,确保 working directory clean 才进行操作。
    alexrezit
        26
    alexrezit  
    OP
       2013-01-17 11:52:24 +08:00
    @chloerei
    我手太快了... orz
    swulling
        27
    swulling  
       2013-01-17 12:06:28 +08:00   ❤️ 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-01-17 12:07:29 +08:00
    @alexrezit
    @chloerei
    唯一的缺点就是目录结构和文件名都没了,不过相信也是一大帮助吧。。。

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


    @qiukun
    你是神马专业的啊?
    还是好好学 git 吧, 这个无所谓轻量不轻量的.
    swulling
        33
    swulling  
       2013-01-17 13:41:00 +08:00   ❤️ 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-01-17 13:53:50 +08:00
    @alexrezit 计算机科学与技术,嗯,下个 project 好好学 git
    @swulling 0 0 那下次扔硬币决定用哪个
    alexrezit
        35
    alexrezit  
    OP
       2013-01-17 15:51:35 +08:00
    @swulling
    Thanks. 已加入我的 vimrc.

    @qiukun
    原来是妓院的... 如果你真的是大一的话, 应该还在宏福吧? 和我们软院的苦逼同学们在一个校区... = =
    sutar
        36
    sutar  
       2013-01-17 17:04:27 +08:00
    @qiukun hg也可以考虑
    alexrezit
        37
    alexrezit  
    OP
       2013-01-17 17:55:44 +08:00
    @sutar
    hg 不如 git.
    wgziOS
        38
    wgziOS  
       2017-06-01 09:06:58 +08:00
    @swulling 说的对
    YIFEIO
        39
    YIFEIO  
       2018-01-21 17:08:46 +08:00
    杯具。。。我写了一周的代码没了,幸亏只是用来学习的一个小项目
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5318 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 03:44 · PVG 11:44 · LAX 20:44 · JFK 23:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.