从Git历史记录中删除具有历史记录的特定文件 [英] Removing a specific file with its history from the Git history

查看:300
本文介绍了从Git历史记录中删除具有历史记录的特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除很久以前我的Git存储库中特定文件的修订历史记录。目标是使它看起来像文件从未提交特定修订。有谁知道如何做到这一点?谢谢!

解决方案

听起来像是你想 git filter-branch

不过,请务必考虑手册页上的警告:


警告!重写后的历史记录
对于所有
对象都有不同的对象名称,并且不会与原始分支的
汇合。您不会是
能够轻松地将
重写的分支推送并分配到
原始分支之上。如果您不知道
的全部影响,请不要使用
这个命令,如果简单的单一提交
就足以解决您的问题,请避免使用

(有关重写
发布历史的更多信息,请参阅git-rebase(1)中的从UPSTREAM
REBASE中恢复一节,以了解
。)


示例手册页的部分显示了如何删除给定文件的历史记录。这应该是一个很好的起点。


假设您要删除文件
(包含机密信息

$ b

git filter-branch --tree-filter'rm
文件名' - --all



I want to delete the revision history for a specific file in my Git repository that was made long ago. The goal is to make it look like the file was never committed for a specific revision. Does anyone know how to do this? Thanks!

解决方案

Sounds like you want git filter-branch.

However, please be sure to consider the warning on the man page:

WARNING! The rewritten history will have different object names for all the objects and will not converge with the original branch. You will not be able to easily push and distribute the rewritten branch on top of the original branch. Please do not use this command if you do not know the full implications, and avoid using it anyway, if a simple single commit would suffice to fix your problem. (See the "RECOVERING FROM UPSTREAM REBASE" section in git-rebase(1) for further information about rewriting published history.)

The "Examples" section of the man page shows how to remove history for a given file. This should be a good starting point for you.

Suppose you want to remove a file (containing confidential information or copyright violation) from all commits:

git filter-branch --tree-filter 'rm filename' -- --all

这篇关于从Git历史记录中删除具有历史记录的特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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