【问题标题】:Is there a reflog for the index?是否有索引的 reflog?
【发布时间】:2016-11-08 11:24:23
【问题描述】:

我手头没有具体问题,但我在过去遇到过一些我不小心炸毁索引的情况,并希望我可以返回给定文件的先前状态,该文件在某些​​位置被索引点。

一些例子是:

$ git add <file>
# find out that I already had an indexed version of <file>,
# and that for some reason I shouldn't have added the extra modifications

$ git stash pop
# find out afterwards that I have a mix of "the index I had"
# and "the index in the stash"

$ git stash
# with an active index, which is now mixed with the state of the working tree

$ git reset <typo>
# accidentally resetting the wrong file, or the whole directory

可以求助于挖掘git fsck --full --unreachable --no-reflog(建议here),我想知道是否有更方便的方法来做到这一点。

问题:

索引是否有某种 reflog?

【问题讨论】:

    标签: git git-index git-reflog


    【解决方案1】:

    reflog 包含 refs 的条目...而不是索引。

    但是,也许工作流程调整是这里的答案......(对我来说)。

    如果工作时间超过 5 到 10 分钟,commit-as-you-go(并在推送前进行清理)。否则,即兴表演

    index 很棒……我整天都在用它!但只有当我知道我将在一两分钟内提交(基本上是原子工作流操作)时,我才会真正使用它。这是因为我害怕我会做一些愚蠢的事情并毁掉我的索引。

    在我工作的时候,每当我达到一个小里程碑时,我都会进行一次私人提交,通常在我有机会先进行一些清理之前不会推送该提交。在解决特定问题时,我会不断做出承诺,通常会进行修改。

    然后,一旦我真正达到了我想要创建公共提交的稳定点,我将(如果需要)我所有的小 wip 提交压缩在一起,给出一个很好的提交消息并推送。

    如果需要的话,这提供了在我的 reflog 中创建小面包屑的巨大优势。

    这是我的工作流程:

    # start work
    git checkout -b featurea
    # work
    vim file.txt
    # reach a little milestone
    git commit -a -m "working on feature..."
    # work some more
    vim file.txt
    # reach another little milestone
    git commit -a --reuse-message=HEAD --amend
    # work some more
    vim file.txt
    # another little milestone...
    git commit -a --reuse-message=HEAD --amend
    # finishing touches...
    vim file.txt
    # ok, done now, put everything back in working dir so I can review
    git reset HEAD~
    # decide what goes in this commit
    # perhaps use `git add -p`
    git add file.txt
    # give a nice commit message (use editor)
    git commit
    # now merge to master and push with confidence!
    

    这可能看起来需要大量的输入,但如果你擅长在 shell 上飞行(利用 set -o emacsset -o vi 是一个好方法),那么这种方法几乎是即时的。

    如果我的工作确实是一个非常快速的解决方案,我通常会使用即用即用的方法,但除此之外,我需要安全地在我进行时填充我的 reflog。

    【讨论】:

    • 工作流程+1。此外,对于较长的任务(任何可能需要一天以上,有时甚至超过几个小时的任务),请创建本地分支。 Git 的分支几乎是免费的:它们确实占用了一些磁盘空间,但我发现它们最昂贵的资源是我自己的头部空间(“嗯,我有 experiment1experiment45,太好了,现在 到底是什么我正在试验?)...
    • @torek 跑题了——但是你的 git 书什么时候出版? :-)
    • @Alok-- 我找到了一份全职工作,但工作却停滞不前,唉!
    • @torek 感谢您的留言!如果需要,我可以帮助处理琐碎的部分:-)
    【解决方案2】:

    不,索引没有引用日志。您将不得不按照我们的方式解决问题,如您在命令中使用git fsck 或不使用--lost-found 标志。

    您可以使用文件的时间戳 (SHA-1) 按创建日期对文件进行“排序”,并根据文件创建时间进行一些基本的 reflog。

    【讨论】:

    • 为了测试,我尝试查找我的fsck --unreachable 返回的所有.git/objects/ab/cdef... blob。一些悬垂的 blob 不存在,这可能意味着它们存储在包文件中。你知道找到 blob 所属包文件的快速方法吗?
    • 我正在寻找文件的修改日期。您是否有其他技巧来查找 blob 的修改日期?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多