从git svn clone中排除文件 [英] Exclude files from git svn clone

查看:428
本文介绍了从git svn clone中排除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个SVN回购站迁移到Git,并且我希望排除7000多个二进制文件,从一开始就不需要导入并成为Git历史记录的一部分,而不是将它们清理干净(参考问题)。这些文件的位置并不遵循一个非常规的模式,所以我不得不提供一个长长的git位置列表,并且我有〜8000个提交要考虑的事项。



如果我的目标是避免使用不必要的文件来扩大回购,那么最佳方法是什么?



有没有一种方法可以将它们从一开始排除,也许作为git svn clone的标志?在克隆之前将它们添加到 .gitignore 会阻止它们被添加?

另一种选择是导入全部,然后用 git filter-branch 重写整个历史记录以删除全部这些文件在与他人共享回购前。

解决方案

根据您的问题和意见,我不认为有办法简单地克隆,不需要某些你不想要的文件。



我相信只要将这些文件放入gitingore文件中对你所做的git克隆没有任何影响到回购。



但是,在服务器上,您可能会创建一个没有这些文件的过滤分支,您可以从中获取这些文件这个问题的答案暗示了他们类似的问题:


在服务器上:

  git checkout master ^ 0#the ^ 0检出提交本身,而不是分支
git fil ter-branch --tree-filter'git rm -r wp-content / uploads'HEAD
git checkout -b filtered

(在一个大项目中的filter-branch会以每秒2-3次提交的方式产生新的历史记录)

然后,在任何你喜欢的地方,
git init
git remote add gimme your:// repo / path
git fetch gimme filtered

正如文档所述,filter-branch命令对于以下内容似乎很好地包含了你所处的情况:


这些过滤器可以修改每个树(例如删除文件或在所有文件上运行perl重写)或关于每个提交的信息。否则,将保留所有信息(包括原始提交时间或合并信息)。







编辑:这有额外的好处,如果您想从将来的回购协议拉回到其他地方,那就更简单了,因为这是一次性解决方案,适用于原始回购协议,而不是为每个单独的克隆完成一些事情。


I'm migrating an SVN repo to Git and I have 7000+ binary files I would like to exclude from being imported and becoming part of the Git history from the start, as opposed to cleaning them up after (ref this question). The location of the files doesn't follow a very regular pattern so I'd have to supply a rather long list of locations to git, and I have ~8000 commits to take into consideration.

If my goal is to avoid bloating the repo with unnecessary files, what is the best approach to do that ?

Is there a way I can exclude these from the start, perhaps as a flag to git svn clone ? Would adding them to a .gitignore before clone prevent them from being added ?

The other option would be to import all, then rewrite the whole history with git filter-branch to remove all those files before sharing the repo with others.

解决方案

Based on your question and comments I don't think there is a way to simply clone without the certain files you don't want.

I believe that just placing the files into the gitingore file won't make any difference to the git clone you do to the repo.

However, on the server you may be able to create a filtered branch that doesn't have these files that you can pull from, as one of the answers on this question suggest suggests for their similar problem:

On the server:

git checkout master^0    # the ^0 checks out the commit itself, not the branch
git filter-branch --tree-filter 'git rm -r wp-content/uploads' HEAD
git checkout -b filtered

(filter-branch on a big project here generates new history at about 2-3 commits per second)

Then, anywhere you like, git init git remote add gimme your://repo/path git fetch gimme filtered

As the documentation says, the filter-branch command can be useful for the following, which seems to nicely include the situation you're in:

Those filters can modify each tree (e.g. removing a file or running a perl rewrite on all files) or information about each commit. Otherwise, all information (including original commit times or merge information) will be preserved.


Edit: This has the additional bonus that if you want to pull from this repo in the future to additional places, then it's much simpler because it's a one time fix that you apply to the original repo rather than something done for each individual clone.

这篇关于从git svn clone中排除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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