在我的 Git 分支上,我创建了一个提交并推送。后来,我对索引添加了更改,使用 git commit --amend ,然后使用 git push -f 。我的新提交在本地和远程分支上都覆盖了第一个提交。
此时,我期望(或希望)原始提交不再存在,或者至少存在(可能在引用日志中)但不再有父级,因此,一旦我运行 GC,它就会不复存在。然而,提交似乎仍然存在,并且其父级仍然完好无损。 (在这种情况下,我发现它的方式是通过 Jira,它将我链接到 github 上被覆盖的提交)
为什么会这样呢?怎么会被删除呢?这是否意味着,每当我不小心将密码推送到 GitHub,然后使用 git commit --amend
或 git reset
,然后 git push -f
,提交实际上从未真正被删除?
最佳答案
来自 git help gc
:
--prune=<date>
Prune loose objects older than date (default is 2 weeks ago, overridable by the config variable gc.pruneExpire).
--prune=all
prunes loose objects regardless of their age.--prune
is on by default.
所以你可能想运行 git gc --prune=all
.
关于Git - 修改后的提交是否持续存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32500640/