使用GIT子目录过滤器保留原始文件夹

问题描述 投票:0回答:1

我有以下文件夹结构:

Folder1
 -> SubDirectory1
   -> File1
   -> File2
 -> SubDirectory2

我需要过滤结构,以便只留下 SubDirectory1 及其内容。

我正在使用:

git filter-branch -f --subdirectory-filter "Folder1/SubDirectory1" --prune-empty --tag-name-filter cat -- --all

问题是 SubDirectory1 文件夹也被删除,我需要它。我使用什么开关来保留 SubDirectory1 文件夹?

git git-filter-branch
1个回答
0
投票

您可以创建一个新的空分支,然后使用

subtree add
添加与该文件夹相关的提交。

git subtree add --prefix=ansible another-branch

或者要从另一个远程导入按文件夹过滤的提交,请尝试:

git remote add other-repo [email protected]:org/repo.git
git subtree add --prefix=ansible remotes/other-repo/master
© www.soinside.com 2019 - 2024. All rights reserved.