是否有索引的reflog?

时间:2016-07-06 12:01:18

标签: git git-index git-reflog

我手边没有特定的问题,但是我在过去遇到过一些我意外炸毁索引的情况,并且希望我可以回到给定文件的先前状态,该文件被索引点。

一些示例案例是:

$ 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?

2 个答案:

答案 0 :(得分:3)

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

但是,也许工作流程调整就是答案......(这对我而言)。

如果需要花费超过5-10分钟的时间, 提交即用 (并在推送之前进行清理)。否则,分阶段进行

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是一个好方法),那么这种方法几乎是即时的。 / p>

如果我正在进行的工作是一个非常快速的解决方案,我通常会使用阶段性的方法,但是比我更长的时间我需要在我去的时候填充我的reflog的安全性。

答案 1 :(得分:1)

不,索引没有reflog。当您使用带有git fsck标志或不带--lost-found标志的makefiles时,您将不得不解决这个问题。

您可以使用文件的时间戳(SHA-1)到&#34;排序&#34;创建日期之前的文件,并根据文件创建时间有一些基本的reflog。