简体   繁体   English

没有历史的git分支

[英]git branch without history

My git repo contains sensitive passwords which, for reasons out of my control, can't be removed right now. 我的git repo包含敏感密码,由于我无法控制的原因,这些密码现在无法删除。 Right now it's all OK because this repo is internal-only, but I've been asked to create a branch that's safe to share with partners. 现在一切都好,因为这个回购只是内部的,但我被要求创建一个可以安全地与合作伙伴共享的分支。

Is there any way to create a branch in git and then remove files from it in a way where they can't be retrieved using the log? 有没有办法在git中创建一个分支,然后以无法使用日志检索它们的方式从中删除文件?

Seems like a long shot, but thought I'd ask. 看起来像是一个长镜头,但我想我会问。 The only solution I can think of is to copy the file tree to a new git repo without the sensitive file--but then I'd lose the ability to merge partner changes back to my repo. 我能想到的唯一解决方案是将文件树复制到没有敏感文件的新git仓库 - 但是我失去了将伙伴更改合并回我的仓库的能力。

One thing you could do is create a branch of your repo, edit out the passwords, and then create a shallow clone (with depth 1) of that repository that you would give to the partners. 您可以做的一件事是创建一个repo分支,编辑密码,然后创建一个您将给合作伙伴的存储库的浅层克隆(深度为1)。 They can make patches and whatnot against that clone, but can't see the whole history and can't push the repo anywhere else. 他们可以制作补丁和针对该克隆的东西,但无法看到整个历史记录,也无法在其他任何地方推送回购。 If they're just making changes, then this should be a workable solution. 如果他们只是做出改变,那么这应该是一个可行的解决方案。 You can still accept patches from them and apply to your master repository. 您仍然可以接受来自它们的补丁并应用于主存储库。

See the --depth option of git clone for further information. 有关详细信息,请参阅git clone--depth选项。

Use filter-branch : 使用filter-branch

Suppose you want to remove a file (containing confidential information or copyright violation) from all commits: 假设您要从所有提交中删除文件(包含机密信息或侵犯版权):

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

git clone --depth 1 url_of_your_remote_repository git clone --depth 1 url_of_your_remote_repository

Limitation of shallow repository 浅存储库的局限性

  • you can't clone or fetch from the shallow repository(That means you can't make a new repository using this shallow copy) 您无法从浅存储库中克隆或获取(这意味着您无法使用此浅副本创建新的存储库)

  • you could not able to view whole history using git log command. 您无法使用git log命令查看整个历史记录。

  • Its workable solution, your partner can make some changes and make it as "patches" and send it to you partner if you wants your partner changes. 它的可行解决方案,您的合作伙伴可以进行一些更改并将其作为“修补程序”并将其发送给您的合作伙伴,如果您希望更改合作伙伴。 Then apply that patches in your current working tree/ whatever branches you want to apply. 然后将这些修补程序应用于当前工作树/要应用的任何分支。

    More 更多

I'll take a stab at a couple answers. 我会抓住几个答案。 Let us assume that you can create a branch that doesn't contain sensitive data. 我们假设您可以创建一个不包含敏感数据的分支。 You cloud then make a shallow clone of the branch which would not contain history and therefore you could not pull from it, but it could pull form you. 你云然后做一个不包含历史的分支的浅克隆,因此你不能从它拉,但它可以拉你形成。

The other thing would be to clone a new repository and use the git removal tools to expunge sensitive data. 另一件事是克隆一个新的存储库并使用git清除工具来清除敏感数据。 This would create a distinct repository that could not interact except through patches with the first, but would have all the history. 这将创建一个不同的存储库,除了通过第一个补丁,但将具有所有历史记录之外无法进行交互。

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

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