V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ljxok2001
V2EX  ›  问与答

Git 误删了代码,如何找回?

  •  
  •   ljxok2001 · Apr 15, 2020 · 3577 views
    This topic created in 2205 days ago, the information mentioned may be changed or developed.

    手贱执行了个 git 命令:git clean -fdx,然后很多没 add 到版本控制中的文件被清掉了,google 了很久,都说这些用 git 是找不回这些误删文件了。

    那么,有没有如下的可能:

    1 、由于我的大部代码都是 javascript,在 chrome 打开过页面,有没办法从 chrome 缓存文件中回这些文件?我的系统是 Mac OS.

    2 、Mac OS 有没有办法用文件系统来恢复这些误删文件?或者有没哪个文件恢复工具?

    10 replies    2020-04-15 11:02:33 +08:00
    Trim21
        1
    Trim21  
       Apr 15, 2020
    看看 ide 有没有文件缓存。。。
    pkuphy
        2
    pkuphy  
    PRO
       Apr 15, 2020
    有开时间机器吗?

    使用 IDE 了吗? IDE 比如 WebStorm 是有历史记录的
    Trim21
        3
    Trim21  
       Apr 15, 2020
    @Trim21 文件缓存->文件历史
    msg7086
        4
    msg7086  
       Apr 15, 2020 via Android
    这些文件有没有被 git 曾经 stash 过?
    Mutoo
        5
    Mutoo  
       Apr 15, 2020
    如果你用的是 JetBrains 家的 IDE,VCS 菜单下有一个 Local History,可以恢复被删除的文件,即使没有加入到 git 也行。
    ycr6708536
        6
    ycr6708536  
       Apr 15, 2020
    提交过的话可以看下 reflog
    sunziren
        7
    sunziren  
       Apr 15, 2020
    把硬盘拔下来,送去淘宝数据恢复
    unsized
        8
    unsized  
       Apr 15, 2020
    昨天 `git checkout -- .` 然后靠 PyCharm Local History 找回的路过。。
    crazybinggan
        9
    crazybinggan  
       Apr 15, 2020
    我昨天 git reset --hard,一周的代码全没了(因为很多关联,不好细粒度提交,需要整块完成),还好开着 JB,有 local history,损失了部分代码,但是万幸有这玩意,不然真跪了。

    git reflog 结合我自身的操作,只能是本地 commit 过之后的可以。
    dilu
        10
    dilu  
       Apr 15, 2020
    #5 楼是正确方案,Jetbrains 家的 IDE 的文件历史很好用
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   974 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 20:11 · PVG 04:11 · LAX 13:11 · JFK 16:11
    ♥ Do have faith in what you're doing.