V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wingoo
V2EX  ›  问与答

git数据丢失求助下

  •  
  •   wingoo · 2013-12-10 19:42:20 +08:00 · 3260 次点击
    这是一个创建于 3814 天前的主题,其中的信息可能已经有所发展或是发生改变。
    写了几天的代码没commit
    刚出去吃饭, 锁定机器
    回来后更新了一个其他人提交的版本
    发现我没签入的代码都没了,
    项目目录底下也没有了
    有没办法恢复?

    谢谢

    环境, windows 7 + phpstorm
    14 条回复    2014-11-05 23:43:28 +08:00
    detailyang
        1
    detailyang  
       2013-12-10 19:50:05 +08:00
    坐等高人解答。。我知道总有一天我也会这样 = =。。因为最近直接rm了忘记提交的代码:(
    wingoo
        2
    wingoo  
    OP
       2013-12-10 20:22:44 +08:00
    update下, 所有新增的文件丢失, 修改的还在
    用数据恢复软件, 检查项目目录, 没有记录..
    9hills
        3
    9hills  
       2013-12-10 20:37:14 +08:00 via iPad
    如果stage了是可以找回的,如果连git add 都没做。。。就杯具了


    git一定要多commit 然后rebase写commit


    另外工作区又没有commit的代码的时候是不能做很多操作的,想知道怎么更新的他人代码
    wingoo
        4
    wingoo  
    OP
       2013-12-10 20:39:38 +08:00
    @9hills 用的是phpstrom, git add应该是自动做的
    更新代码, 也是用的phstorm内置的

    怎么检查git add之后的记录呢?
    谢谢
    9hills
        5
    9hills  
       2013-12-10 20:48:38 +08:00 via iPad   ❤️ 1
    @wingoo
    git reflog 能找到那些丢失的commit 注意是commit stage的不行
    而 git fsck --lost-found 能找到所有在stage中删掉的文件
    9hills
        6
    9hills  
       2013-12-10 20:50:21 +08:00 via iPad
    wingoo
        7
    wingoo  
    OP
       2013-12-10 21:07:32 +08:00
    @9hills 恩, 多谢
    wingoo
        8
    wingoo  
    OP
       2013-12-10 21:25:13 +08:00
    @9hills 这是git status的输出, 运行git fsck --lost-found 没有找到丢失的文件...是不是杯具了,,
    $ git status
    # On branch master
    # Changes to be committed:
    # (use "git reset HEAD <file>..." to unstage)
    #
    # new file: protected/controllers/SearchController.php
    # new file: protected/models/Search.php
    #
    # Changes not staged for commit:
    # (use "git add/rm <file>..." to update what will be committed)
    # (use "git checkout -- <file>..." to discard changes in working direct
    #
    # modified: README
    # deleted: protected/controllers/SearchController.php
    # deleted: protected/models/Search.php
    #
    # Untracked files:
    # (use "git add <file>..." to include in what will be committed)
    #
    # .idea/
    9hills
        9
    9hills  
       2013-12-10 21:51:20 +08:00 via iPad
    只要add过肯定能找回的 fsck 出来的文件名都变了,耐心找
    wingoo
        10
    wingoo  
    OP
       2013-12-10 21:58:44 +08:00
    @9hills 是只执行 git fsck --lost-found 这个操作吗?
    恢复出来就几个文件, 没个都看了.. 不是
    wingoo
        11
    wingoo  
    OP
       2013-12-10 22:23:26 +08:00
    @wingoo 我运行 git fsck --cache --no-reflogs --lost-found --unreachable HEAD
    后有一堆文件出啦, 但没有输出到lost-found文件夹
    类似
    Checking object directories: 100% (256/256), done.
    Checking objects: 100% (10613/10613), done.
    unreachable tree 018098c43dcbd321dd904d8d274b0a1cdd6cff02
    unreachable blob 8100e5dd835d1a9331dde246347cf4fac73d7655
    unreachable blob 9d00d90fe12bc079e3a97eac906dea47a862a190
    unreachable commit 08c1e8b48bb4fb2a15bd0675cafdb757b21aa590
    unreachable blob 0d4145d4e0ba97fca67bc865a4c5bb3a76bef5ce
    尝试打开了几个, 发现有几个丢的文件, 有没有办法全部输出到文件夹去?
    谢谢
    9hills
        12
    9hills  
       2013-12-10 23:03:27 +08:00 via iPad
    @wingoo 首先你stage区的那两个文件恢复了么

    # new file: protected/controllers/SearchController.php
    # new file: protected/models/Search.php
    wingoo
        13
    wingoo  
    OP
       2013-12-11 12:06:41 +08:00
    @9hills 找到了大部分新增文件, 有些修改的没找到..
    多谢帮助:)
    elvba
        14
    elvba  
       2014-11-05 23:43:28 +08:00
    @9hills 感谢!
    今天我也碰到这种情况,差点都哭了TAT
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5188 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 01:39 · PVG 09:39 · LAX 18:39 · JFK 21:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.