具有现有目录结构的Git子目录过滤器 [英] Git subdirectory filter with existing directory structure

查看:142
本文介绍了具有现有目录结构的Git子目录过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用filter-branch的--subdirectory-filter选项拆分出一个Git仓库,该仓库运行良好,除了将所有内容都提交到仓库的根目录。



我现在有

  ABC 
- DEF
- GHI
- JKL
- MNO

以及此命令的结果:

  git filter-branch -f --subdirectory-filter ABC / DEF --prune-empty  -  --all 



生成此:

  GHI 
JKL

我真正想要的是这样的:

  ABC 
- DEF
- GHI
- JKL

在Git文档中我看不到任何显示保留(或设置)目录结构的过滤器选项的文档,而且我无法找到可以运行的命令过滤后重新映射结构以达到我想要的状态。



这是可能的吗?

解决方案

我找到了答案在这里这个技巧。



命令:

  git filter-branch -f --index-filter'git ls-files -s \ 
| seds-\t-&ABC / DEF / - \
| GIT_INDEX_FILE = $ GIT_INDEX_FILE.new git update-index --index-info \
&& mv $ GIT_INDEX_FILE.new $ GIT_INDEX_FILE'

完美无缺


I'm splitting out a Git repository using the --subdirectory-filter option of filter-branch which is working great except it pulls everything up to the root of the repository.

I currently have

ABC
  - DEF
      - GHI
      - JKL
  - MNO

And the result of this command:

git filter-branch -f --subdirectory-filter ABC/DEF --prune-empty -- --all

Generates this:

GHI
JKL

Where what I really want is this:

ABC
  - DEF
      - GHI
      - JKL

I can't see anything in the Git docs that shows a filter option which preserves (or sets) the directory structure and I haven't been able to find a command I can run after the filtering to remap the structure to how I want it.

Is this possible?

解决方案

I found an answer here which does the trick.

The command:

git filter-branch -f --index-filter 'git ls-files -s \
| sed "s-\t-&ABC/DEF/-" \
| GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info \
&& mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE'

works perfectly

这篇关于具有现有目录结构的Git子目录过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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