简体   繁体   English

如何从 Gitlab 中完全删除旧提交?

[英]How to completely remove old commits from Gitlab?

I have a repository on Gitlab with some commits on one branch as follows我在 Gitlab 上有一个存储库,其中一个分支上有一些提交,如下所示

A - B - C - D - HEAD

I mistakenly uploaded some secret token string on commit B, and I noticed later on, so I created a new branch from A then copied manually all files from commit D so history now looks like this我错误地在提交 B 上上传了一些秘密令牌字符串,后来我注意到了,所以我从 A 创建了一个新分支,然后手动复制了提交 D 中的所有文件,所以历史现在看起来像这样

 /  - E - HEAD
A  - B  - C - D

Now what i did is to delete on Gitlab the branch BCD so those "token commits" are no longer accessible, and the history looks like现在我所做的是在 Gitlab 上删除分支 BCD,这样那些“令牌提交”就不再可以访问了,历史看起来像

A - E - HEAD

However, I just noticed that I can still access the troublesome commits through Project -> Activity and seeing there my old pushes where the old commits are still accessible.但是,我只是注意到我仍然可以通过 Project -> Activity 访问麻烦的提交,并在那里看到我的旧推送仍然可以访问旧提交。

How can I completely delete those?我怎样才能完全删除那些?

As you have noticed, GitLab holds onto git references in some circumstances, even if you delete those commits and force push over all your branches.正如您所注意到的,GitLab 在某些情况下会保留 git 引用,即使您删除这些提交并强制推送所有分支也是如此。 Besides the activity page you mentioned, this will also include things like MR diffs, pipeline refs, and more.除了您提到的活动页面,这还将包括 MR 差异、管道参考等内容。

This is also apparent when committing large files -- simply deleting the commits and force pushing won't reduce the project storage size!这在提交大文件时也很明显——简单地删除提交并强制推送不会减少项目存储大小!

To completely remove the contents from the GitLab project, you need to follow this guide for purging repository history.要从 GitLab 项目中完全删除内容,您需要按照本指南清除存储库历史记录。 After you initiate the project cleanup by uploading the filter file, all the various commit references will be deleted and the contents are completely gone and inaccessible.通过上传过滤器文件启动项目清理后,所有各种提交引用都将被删除,内容完全消失且无法访问。

You may still see commit hashes and messages in the activity page, but the links will not show any of the contents of those commits because they have been deleted.您可能仍会在活动页面中看到提交哈希和消息,但链接不会显示这些提交的任何内容,因为它们已被删除。

As noted in the docs:如文档中所述:

This process is not suitable for removing sensitive data like password or keys from your repository.此过程不适合从存储库中删除敏感数据,例如密码或密钥。 Information about commits, including file content, is cached in the database, and remain visible even after they have been removed from the repository.有关提交的信息(包括文件内容)缓存在数据库中,即使从存储库中删除后仍然可见。

So, as mentioned in this answer the first step you should take is to rotate your compromised credentials.因此,如本答案中所述,您应该采取的第一步是轮换被盗用的凭据。

If it is important to you to completely remove even the commit messages and hashes in the activity page and database references, your only option would be to migrate/delete and re-create the project (after purging the git history).如果完全删除活动页面和数据库引用中的提交消息和哈希对您很重要,那么您唯一的选择是迁移/删除并重新创建项目(在清除 git 历史记录之后)。 But this will also remove things like issues, merge requests, etc.但这也会删除问题、合并请求等内容。

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

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