如何从git上的filter-branch命令中删除重复的提交? [英] How to remove duplicated commits from filter-branch command on git?

查看:93
本文介绍了如何从git上的filter-branch命令中删除重复的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个django项目,我长期保密。通过项目的生命周期,我有 settings.py base_settings.py secret_settings.py 包含敏感信息的文件。现在我决定让代码开放源代码,因为我不再积极地处理这个项目。



我运行了下面的命令来删除这些文件的历史记录确保所有的敏感信息都没有了。



pre $ g $ c $ git filter-branch -f --tree-filter'rm -f exchange / secret_settings .py'HEAD
git filter-branch -f --tree-filter'rm -f exchange / base_settings.py'HEAD
git filter-branch -f --tree-filter'rm -f exchange /settings.py'HEAD

然而,github警告我还有提交.py〜文件与他们的AWS信息,所以我跑了:

  git filter-branch -f --tree-filter'rm -f exchange /settings.py~'HEAD 

我保护了我的AWS账户并从AWS中删除了所有密钥所以我的帐户是安全的。然而,现在我已经为我的整个提交历史记录重复了提交,有时候是3或4。



我发现了各种答案,说我可以恢复到 .git / refs 备份,但似乎没有工作。



以下是该项目: https:// github。 com / ProgrammingJoe / Texchange



有谁知道我能做些什么来解决这个问题? >解决方案

我在jhill的评论中做了一些更多的搜索,并且在一个新的分支上运行了下面的命令:

  git filter-branch -f --tree-filter'rm -f exchange / settings.py'HEAD 
git filter-branch -f --tree-filter'rm -f exchange / settings。 py〜'HEAD
git filter-branch -f --tree-filter'rm -f exchange / base_settings.py'HEAD
git filter-branch -f --tree-filter'rm -f exchange /base_settings.py~'HEAD
git filter-branch -f --tree-filter'rm -f exchange / secret_settings.py'HEAD
git filter-branch -f --tree-filter'rm -f exchange / secret_settings.py〜'HEAD

之后,我的新分支回到了我想要的地方,大约有300次提交。然后我必须弄清楚如何用这个其他分支完全覆盖主人。在良好的实践中,我将我的回购在另一个位置作为备份。然后我尝试了每个组合的推动和合并,我可以覆盖主分支,没有任何工作。然后我问了这个问题: Github,我的分支在主人后面,但它是正确的。如何覆盖分支的主人?

然后我意识到,我在主人的一些较旧的提交是我想要他们的地方,所以我跑了:

p>

  git checkout master 
git reset --hard correct_commit_id
git push -f原点大师

这解决了我所有的问题,但是我不小心删除了我以前使用过的一个文件。好东西,我有一个备份:)。我不知道为什么 git reset --hard fixed_branch 在过去并不奏效。


I have a django project that I've kept private for a long period of time. Through the lifespan of the project I've had settings.py, base_settings.py, and secret_settings.py files with sensitive information. Now I've decided to make the code open source as I am no longer actively working on the project.

I ran the commands below to remove the history of these files to make sure all sensitive information was gone.

git filter-branch -f --tree-filter 'rm -f exchange/secret_settings.py' HEAD
git filter-branch -f --tree-filter 'rm -f exchange/base_settings.py' HEAD
git filter-branch -f --tree-filter 'rm -f exchange/settings.py' HEAD

However, github warned me that there was still commits that had .py~ files with AWS information in them so I ran:

git filter-branch -f --tree-filter 'rm -f exchange/settings.py~' HEAD

I have secured my AWS account and removed all the secret keys from AWS so my account is secure. However, now I have duplicated commits, sometimes 3 or 4, for my entire commit history.

I've found various answers saying I can revert back to some .git/refs backups but that doesn't seem to be working.

Here is the project: https://github.com/ProgrammingJoe/Texchange

Does anyone know what I can do to fix this?

解决方案

I ended up doing some more googling after jhill's comment and I ran the following commands on a new branch:

git filter-branch -f --tree-filter 'rm -f exchange/settings.py' HEAD       
git filter-branch -f --tree-filter 'rm -f exchange/settings.py~' HEAD       
git filter-branch -f --tree-filter 'rm -f exchange/base_settings.py' HEAD       
git filter-branch -f --tree-filter 'rm -f exchange/base_settings.py~' HEAD       
git filter-branch -f --tree-filter 'rm -f exchange/secret_settings.py' HEAD       
git filter-branch -f --tree-filter 'rm -f exchange/secret_settings.py~' HEAD       

After that, my new branch was back where I wanted it with around 300 commits. I then had to figure out how to completely overwrite master with this other branch. In good practice, I cloned my repo in another location as a backup. I then tried every combination of force pushing and merging I could to overwrite the master branch and nothing worked. I then asked this question: Github, my branch is behind master but it is correct. How do I overwrite master with the branch?

I then realized that some of my older commits in master were where I wanted them so I ran:

git checkout master
git reset --hard correct_commit_id
git push -f origin master

This fixed all my issues but I accidentally deleted one of the files I used to have. Good thing I had a backup :). I'm not sure why git reset --hard fixed_branch didn't work in the past.

这篇关于如何从git上的filter-branch命令中删除重复的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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