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

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

问题描述

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

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中显示"You can only delete files when you are on the branch".在终端中,我找到了命令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

请参阅我想从

Refer to i-want-to-remove-a-large-file-from-ever-existing-in-repo-history of Github: git-flight-rules

推荐技术-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天全站免登陆