【发布时间】:2012-02-07 21:36:40
【问题描述】:
免责声明:此问题仅供参考,并不代表我遇到的实际问题。我只是想弄清楚一些东西(因为我喜欢搞清楚,我知道你也喜欢)。
所以我在玩 git,试图使修改后的提交过期。我的 reflog 看起来像这样:
4eea1cd HEAD@{0}: commit (amend): amend commit
ff576c1 HEAD@{1}: commit: test: bar
5a1e68a HEAD@{2}: commit: test: foo
da8534a HEAD@{3}: commit (initial): initial commit
这意味着我做了两次提交(da8534a 和 5a1e68a),然后是第三次提交 ff576c1,我用 4eea1cd 进行了修改。
正如预期的那样,我的git log 看起来像这样:
* 4eea1cd (HEAD, master) amend commit
* 5a1e68a test: foo
* da8534a initial commit
根据我(尽管我)对提交的过期性的了解,某天(很可能,默认为 30 天)git gc 应该收集到ff576c1。现在我不想等待 30 天才能看到这种情况发生,所以我开始运行一些命令,首先:
git fsck --unreachable --no-reflogs
正如预期的那样,这又给了我:
unreachable blob 5716ca5987cbf97d6bb54920bea6adde242d87e6
unreachable tree 1e60e555e3500075d00085e4c1720030e077b6c8
unreachable commit ff576c1b4b6df57ba1c20afabd718c93dacf2fc6
所有人都确信我将结束那个可怜的孤独ff576c1 提交,然后我运行git reflog expire:
git reflog expire --dry-run --expire-unreachable=now --all
那个时候,给了我:
would prune commit: test: bar
would prune commit (amend): amend commit
起初我虽然我的HEAD 没有引用master,但正如您在我之前给出的git log 输出中看到的那样,它确实如此。此外,cat .git/HEAD 证实了这一点(大喊 ref: refs/heads/master)。无论如何,尽管这很愚蠢,因为4eea1cd 是我的master 分支的负责人。
所以我在这里,很困惑这两个命令不会给我相同的提交,并且想知道 4eea1cd 怎么可能无法访问,因为它是我的 master 分支的实际提示。
知道发生了什么吗?
编辑:我刚刚注意到如果我将--rewrite 选项添加到git reflog expire,就像这样:
git reflog expire --dry-run --expire-unreachable=now --all --rewrite
然后我只得到修改后的提交:
would prune commit: test: bar
我还是不明白,因为根据git help reflog:
--rewrite
While expiring or deleting, adjust each reflog entry to ensure that
the old sha1 field points to the new sha1 field of the previous
entry.
这对我来说没有意义。好吧,至少我不明白,因为显然它确实改变了一些东西。
【问题讨论】:
标签: git reachability reflog