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

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

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

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

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

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


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

    @qiukun
    原来是妓院的... 如果你真的是大一的话, 应该还在宏福吧? 和我们软院的苦逼同学们在一个校区... = =
    sutar
    sutar
    Jan 17, 2013
    36
    @qiukun hg也可以考虑
    alexrezit
    alexrezit
    OP
    Jan 17, 2013
    37
    @sutar
    hg 不如 git.
    wgziOS
    wgziOS
    Jun 1, 2017
    38
    @swulling 说的对
    YIFEIO
    YIFEIO
    Jan 21, 2018
    39
    杯具。。。我写了一周的代码没了,幸亏只是用来学习的一个小项目
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4815 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 115ms · UTC 08:20 · PVG 16:20 · LAX 00:20 · JFK 03:20
    ♥ Do have faith in what you're doing.