代码之家  ›  专栏  ›  技术社区  ›  Ray

在执行git rm时,在提交后在MacOS上还原文件

  •  1
  • Ray  · 技术社区  · 6 年前

    运行MacOS High Sierra 10.13.4和Git版本2.17.0。

    这是我的工作流程:

    • git rm ./some/file.out
    • git status 请注意删除 ./some/file.out 正在等待提交
    • 检查 ls ./some/ 看到文件被删除了
    • git commit 看到消息一个文件被删除

    然而:

    • 如果我跑 GIT状态 我看到文件还在那里,但没有找到。
    • 当运行 git clean -df 在未跟踪的文件上,它会被删除,不会返回。

    我也试过了

    • 删除非git文件 rm ./some/file.out
    • git add . 然后 GIT提交 并查看文件删除消息
    • GIT状态 显示文件仍然存在,但未跟踪

    这似乎是最近才开始发生的。

    这是我的Git配置:

    credential.helper=osxkeychain
    core.hookspath=/Users/myname/.git_hooks
    core.excludesfile=/Users/myname/.gitignore
    user.email=myname@somewhere.com
    color.ui=true
    color.branch=true
    color.status=true
    color.diff=true
    color.interactive=true
    color.grep=true
    color.pager=true
    color.decorate=true
    color.showbranch=true
    alias.pt=!git push -u origin `git rev-parse --abbrev-ref HEAD`
    alias.co=checkout
    alias.cob=checkout -B
    alias.b=branch
    alias.bd=branch -D
    

    可能会发生什么——特别是,有没有其他人看到类似的情况,发现它与Git相关?

    只是删除终端中的文件(非git repo文件)没有这种行为。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Ray    6 年前

    拨弄我的周围 ~/.git_hooks . 看起来像是在我的 ~/.git_hooks/pre-commit.d 文件夹是罪魁祸首。

    不确定脚本到底在做什么(或者应该做什么),但是当我删除脚本时, git rm && git commit 功能按预期工作——没有更多文件从死里复活!