从旧提交中删除文件而不影响 gitlab 中的任何其他提交 [英] Remove a file from a older commit without affecting any other commits in gitlab

查看:14
本文介绍了从旧提交中删除文件而不影响 gitlab 中的任何其他提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 gitlab 存储库来上传我的代码文件.我已经提交了超过 500 次.我的回购大小高达 540 mb.我想通过删除 repo 中不需要的文件来最小化 repo 的大小.

I am using the gitlab repository for uploading my code files. I have made more than 500 commits. My repo size was upto 540 mb. I want to minimize the size of the repo by deleting unwanted files in the repo.

不知何故,我管理并删除了本地文件.现在我当前的文件大小在本地是 10 mb.我推了它,它很好.尽管它显示540mb.我开始知道以前的提交文件拥有存储空间.有一个大小为 400 mb 的 zip 文件在我的旧提交中.

Somehow i managed and deleted the files in my local. Now my current file size is 10 mb in the local. I pushed it and it was good. Eventhough it shows 540mb. I came to know the previous commit files holds the storage. There is a zip file with a size of 400 mb which is in one of my older commit.

我通过使用 shell 脚本找到了提交.我想删除提交中的 zip 文件.但它在gitlab webui中显示只有在分支上才能删除文件".在终端中,我找到了命令 git rm <file_name> 来删除文件.我从提交中获得了文件路径.但我不知道如何在特定提交上使用它.它包含一些重要的文件.我不想玩它.

I found the commit by using the shell script. I want to delete the zip file in the commit. But it shows "You can only delete files when you are on the branch" in the gitlab webui. In the terminal, I found the command git rm <file_name> to remove the file. I got the file path from the commit. But I don't know how to use it on a particular commit. It holds some important files. I don't wanna play with it.

我的问题是:如何在 gitlab 的特定提交中删除某个文件而不影响任何其他提交?我尝试了 Stack Overflow 并找到了一些答案,可以在以前的提交中删除文件,但在旧的提交中没有.帮我解决一些问题.

My question is: how do I remove a certain file in a particular commit in gitlab without affecting any other commits? I tried Stack Overflow and found some answers to delete the file in previous commit but not in the older commit. Help me with some solutions.

推荐答案

不影响提交历史是不可能删除文件的.

It's no possible to delete the file without affect commit history.

要删除历史中的文件,可以使用git内置的git-filter-branch或第三方bfg-repo-cleaner

To delete the file in the history, you can use git built-in git-filter-branch or third party bfg-repo-cleaner

参考 Github: git-flight-rules

recommended-technique-use-third-party-bfg

(master)$ git rm path/to/filetoremove
(master)$ git commit -m "Commit removing filetoremove"
(master)$ java -jar ~/Downloads/bfg.jar --delete-files filetoremove

内置技术-use-git-filter-branch

(master)$ git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch filepattern' --prune-empty --tag-name-filter cat -- --all

这篇关于从旧提交中删除文件而不影响 gitlab 中的任何其他提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆