简体   繁体   English

如何使用不在工作树中的提交清理 git 存储库

[英]How clean git repository with commit which not in work tree

I cleaned the Git repository (Bitbucket cloud) with bfg, but the last commit remained uncleaned (as written in the bfg documentation: By default the BFG doesn't modify the contents of your latest commit on your master (or 'HEAD') branch, even though it will clean all the commits before it.).我用 bfg 清理了 Git 存储库(Bitbucket 云),但最后一次提交仍未清理(如 bfg 文档中所述:默认情况下,BFG 不会修改您在主(或“HEAD”)分支上的最新提交的内容,即使它会清除之前的所有提交。)。

However, I didn't see it and wanted to run git gc in a Bitbucket.但是,我没有看到它并想在 Bitbucket 中运行git gc
For this I did " git reset --hard HEAD " and rolled back to it then " git push --force ".为此,我做了“ git reset --hard HEAD ”并回滚到它,然后“ git push --force ”。
But repository size increased?!但是存储库大小增加了?!

Now I have this commit with the old history left in the repository, and bfg cannot clean it, what should I do?现在我有这个提交,旧历史留在存储库中,bfg 无法清理它,我该怎么办?
How can I remove it, since it is no longer attached to the working tree?我怎样才能删除它,因为它不再附加到工作树上?

You can tell BFG to change the last commit too with the --no-blob-protection flag.您也可以使用--no-blob-protection标志告诉 BFG 更改最后一次提交。 *(This is from the BFG-Repo-Cleander documentation). *(来自 BFG-Repo-Cleander 文档)。

Alternatively, you can create a new commit that removes the bad file and then run BFG normally.或者,您可以创建一个删除坏文件的新提交,然后正常运行 BFG。

Try again, this time using newren/git-filter-repo , which will replace BFG and git filter-branch再试一次,这次使用newren/git-filter-repo它将替换 BFG 和 git filter-branch

As mentioned in its documentation:如其文档中所述:

[there is] an extra steps to delete the other tags and do another gc are still required to clean out the old objects and avoid mixing new and old history before pushing somewhere [有] 删除其他标签并执行另一个 gc 的额外步骤仍然需要清除旧对象并避免在推送某处之前混合新旧历史

git filter-repo does avoid confusing users (and prevent accidental re-pushing of old stuff) due to mixing old repo and rewritten repo together. git filter-repo确实避免了由于将旧的 repo 和重写的 repo 混合在一起而使用户感到困惑(并防止意外重新推送旧的东西)。


Note: on the server side (ie, where you are pushing to), a git gc needs to be run, which is done regularly but not immediately.注意:在服务器端(即您要推送到的地方),需要运行 git gc,这是定期但不是立即完成的。
That is the case for GitHub , as well as BitBucket. GitHub 和 BitBucket 就是这种情况

See Atlassian documentation " How to perform a manual garbage collection on a repository "请参阅 Atlassian 文档“ 如何在存储库上执行手动垃圾收集

Bitbucket implements its own garbage collection logic without relying on git gc anymore (this is achieved by setting the [gc] auto = 0 on all repositories). Bitbucket 实现了自己的垃圾收集逻辑,不再依赖git gc (这是通过在所有存储库上设置 [gc] auto = 0 来实现的)。
When a fork is created, the pruneexpire=never is added to the git configuration and this is removed when the last fork is deleted.创建分叉时,将 pruneexpire=never 添加到 git 配置中,并在删除最后一个分叉时将其删除。

As mentioned here :如此处所述

BitBucket will run git gc themselves in response to doing git reset --hard HEAD~1 (which discards last commit) followed by git push -f . BitBucket will run git gc themselves in response to doing git reset --hard HEAD~1 (which discards last commit) followed by git push -f .

So in your case:所以在你的情况下:

git commit --allow-empty -m "empty commit"
git push

git reflog expire --expire-unreachable="30m" --all
git prune --expire="30m" -v
git gc --prune="30m"
git reset --hard HEAD~1
git push -f

And a git gc should be done on BitBucket side! git gc应该在 BitBucket 一侧完成!

I wrote in bitbucket support, they ran the script "git gc" on server and the old story was cleaned我写在 bitbucket 支持中,他们在服务器上运行脚本“git gc”,旧故事被清理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM