Git - 修改后的提交是否持续存在?

标签 git git-amend

在我的 Git 分支上,我创建了一个提交并推送。后来,我对索引添加了更改,使用 git commit --amend ,然后使用 git push -f 。我的新提交在本地和远程分支上都覆盖了第一个提交。

此时,我期望(或希望)原始提交不再存在,或者至少存在(可能在引用日志中)但不再有父级,因此,一旦我运行 GC,它就会不复存在。然而,提交似乎仍然存在,并且其父级仍然完好无损。 (在这种情况下,我发现它的方式是通过 Jira,它将我链接到 github 上被覆盖的提交)

为什么会这样呢?怎么会被删除呢?这是否意味着,每当我不小心将密码推送到 GitHub,然后使用 git commit --amendgit 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/

相关文章:

git - 如何在不提交/添加任何文件或修改任何文件的情况下检查远程 GIT 存储库权限

git - 配置 Jenkins 和 Git/GitHub

git - 使用 git rebase -i 更改以前提交的代码

git - 在没有打开编辑器窗口的情况下修改 Mercurial 提交?

git - 通过修改提交进行差异化

git 也修改了暂存区中添加的文件

linux - 如何在没有 rm -rf 大锤的情况下删除单个 git 存储库克隆?

git - 如何在mac终端中退出插入屏幕

ruby - 从 github 源安装的 Gem 未在 `gem list` 中显示

Git 修改/改写(不添加/更改文件)