Git:将特定文件和历史记录从一个存储库转移到另一个存储库 [英] Git: Transfer Specific Files and Histories From One Repository to Another

查看:132
本文介绍了Git:将特定文件和历史记录从一个存储库转移到另一个存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我已阅读以下所有内容:
- 是否可以将一堆文件从一个git存储库移动到另一个,同时保留(大多数)历史记录?
- 从Git历史中删除敏感文件及其提交
- 我可以只拉某些文件吗从另一个git仓库?
我一直无法得到任何这些解决方案的工作,可能至少部分是由于我不熟悉先进的 git 命令,例如 git rebase



背景



<在过去的一年里,我一直在一个NPO的网站上为其他一些程序员做志愿者,写作n进去。在此过程中,我开发了一个分布式,模块化,多线程,容错的Web框架,该框架使用并发进程实现,并结合一个反向HTTP代理发送到各个模块。 Web框架是由我编写的,虽然有其他程序员编写的模块。我们所有的修改都被推送到了一个中央git仓库,包括模块,框架,库(jQuery,tinymce等)。

鉴于创建广泛的工作这个框架,以及目前缺乏针对程序员的这种解决方案,我正在考虑以开源方式发布该项目。但是,我只想发布实际的框架,而不是放在回购库中的模块,库或其他东西。特别是,至少有一个模块使用硬编码的身份验证密钥来访问Web API,这是您在公开发布时肯定不会希望拥有的内容(尽管安全问题不足以成为问题的其他程序员在网站上工作)。此外,反向http代理检查cookie的值以允许整个网站受密码保护,cookie的值是硬编码的。



如果可能,拥有git的提交历史将是一项资产,因为它可以向正在调查框架的人员展示其历史,并向他们展示其设计的演变以及所涉及的设计决策。 $ b使用 git ,我该如何只包含特定的文件,以及如何使用这些特定文件的历史,当发布一个正式的内部产品作为开源吗?



奖金:有没有某种方式不包括具体文件中的特定行的历史记录(以及删除行)?

解决方案

最简单的方法是克隆整个回购并学习一些错综复杂 filter-branch



其实并不难。根据布局方式,您可以编写一个小脚本,在创建新历史记录时删除某些文件的存在。如果需要的话,子目录过滤器可以激活部件。



要删除某些行,请使用注释引入你想删除的行,然后 rebase -i that_revision ^ 然后删除它。它会导致一些失败,但他们会很容易照顾。



这些练习非常简单和安全,让你走上一条路通常不用git来探索。我想它会很有趣。 :)

First of all, i've read all of the following: - Is it possible to move a bunch of files from one git repository to another while preserving (most) history? - Remove sensitive files and their commits from Git history - Can I pull only certain files from another git repository? I've been unable to get any of these solutions to work, possibly at least partially due to my unfamiliarity with advanced git commands, such as git rebase.

Background

For the past year, i've been volunteering with a few other programmers on a website for a NPO, written in go. In the process, i've developed a distributed, modular, multi-threaded, fault-tolerant web framework that is implemented using concurrent processes, combined with a reverse http proxy that dispatches to the various modules. The web framework is written by me, although there are modules written by the other programmers. All of our changes have been pushed to one central git repository, including the modules, framework, libraries (jQuery, tinymce, etc).

Given the extensive work involved in creating this framework, and the lack of such a solution for go programmers at the moment, I was considering releasing the project as open source. However, I only want to release the actual framework, not the modules, libraries, or other things that are sitting in the repo. In particular, there is at least one module that uses a hard-coded authentication key in order to access a web API, something that you would certainly not wish to have in a public release (although it's not enough of a security concern to be an issue for the other programmers working on the site). Additionally, the reverse http proxy checks a cookie's value in order to allow the entire site to be password-protected, with the cookie's value being hard-coded.

If possible, having the commit history from git would be an asset, as it would show people who are investigating the framework that it has a history, as well as showing them the evolution of it's design, and the design decisions involved.

Question

Using git, how can I include only specific files, and the history of those specific files, when releasing a formally internal product as open source?

Bonus: Is there some way to not include the history for specific lines in a specific file (as well as removing the lines)?

解决方案

The easiest way to do it is to clone the entire repo and learn some intricacies of filter-branch.

It's actually not that hard. Depending on how it's laid out, you can write a small script that will remove the presence of certain files as it constructs a new history. A subdirectory filter can pul up parts if needed.

For removing some lines, use annotate to find the version that introduced the lines that you want removed, and rebase -i that_revision^ then drop it. It'll cause some rebase failures, but they'll be easy to take care of.

These kinds of exercises are pretty easy and safe and get you down a path you don't typically explore with git. I imagine it'd be a lot of fun. :)

这篇关于Git:将特定文件和历史记录从一个存储库转移到另一个存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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