简体   繁体   English

带有--subdirectory-filter的git filter-branch删除所有文件

[英]git filter-branch with --subdirectory-filter removes all files

I would like to to a pretty standard repository split-up. 我想对标准存储库进行拆分。 The original repository has to following structure: 原始存储库必须具有以下结构:

root
|-AAA
|-BBB
  |-BBB1
  |-BBB2
|-CCC

I tried to extract the directory BBB1 and all its contents into an individual repository using the command 我尝试使用以下命令将目录BBB1及其所有内容提取到单个存储库中

git filter-branch --subdirectory-filter BBB/BBB1 -- --all

which leads to git rewriting a bunch of commits and ends with git's final statement 这导致git重写了一堆提交并以git的最终声明结束

Ref 'refs/heads/master' was rewritten

So this seems perfectly fine for me. 所以这对我来说似乎完全可以。 But when I take a look into the root directory after git has finished, the repository no longer contains any source files but only the .git folder at root . 但是当git完成后查看目录时,存储库不再包含任何源文件,而仅包含root.git文件夹。 Browsing this repository with SourceTree I can see in the log the (probably) correct commits which would have affected BBB1 only, but each commit no longer references any files as they are all gone! 使用SourceTree浏览该存储库,我可以在日志中看到(可能)正确的提交,这些提交只会影响BBB1但是每个提交不再引用任何文件,因为它们已经全部消失了!

What am I doing wrong? 我究竟做错了什么? Why are all the files gone, even the ones I actually filtered for? 为什么所有文件都消失了,甚至包括我实际上过滤过的文件?

Thanks in advance! 提前致谢!

Simon 西蒙

Make sure you are using Unix-style path separators ( / ) even on Windows machines. 确保即使在Windows计算机上也使用Unix样式的路径分隔符( / )。

This results in an empty repo with the correctly-filtered history ( \\ ): 这将导致具有正确过滤的历史记录( \\ )的空存储库:

git filter-branch --subdirectory-filter BBB\\BBB1 -- --all

This results in your sub-directory pulled up to the root of the repo and the correctly-filtered history ( / ): 这将导致您的子目录被拉到存储库的根目录和正确过滤的历史记录( / ):

git filter-branch --subdirectory-filter BBB/BBB1 -- --all

Since you tend to lose the ability to auto-complete when using / directory separation in the Windows command line, it may be easier to create your path and then alter it to Unix-style separation. 由于在Windows命令行中使用/目录分隔时,您往往会失去自动完成的能力,因此创建路径然后将其更改为Unix样式的分隔可能更容易。

Disclaimer 放弃

I know the original question shows / separators, but if you pass \\ separators in the sub-directory argument, you see the exact same end result described, which has me skeptical. 我知道原始问题显示/分隔符,但是如果您在子目录参数中传递\\分隔符,则会看到描述的最终结果完全相同,对此我持怀疑态度。 As soon as you flip to Unix-style / separators on a Windows machine, it works perfectly. 在Windows计算机上切换到Unix风格的/分隔符后,它就可以完美运行。

I have experienced exactly the same problem and was not able to resolve it using filter-branch command nor did I found any explanations for the problem. 我遇到了完全相同的问题,无法使用filter-branch命令解决该问题,也未找到该问题的任何解释。 But there is another way to achieve similar result that has worked for me. 但是有另一种方法可以达到类似的效果,这对我有用。 It's based on a subtree command. 它基于子树命令。 I found a reference to that approach here Detach (move) subdirectory into separate Git repository and an example of using it here https://makingsoftware.wordpress.com/2013/02/16/using-git-subtrees-for-repository-separation/ . 我在此处找到了对该方法的参考, 将子目录分离(移动)到单独的Git存储库中,并在此处使用了该示例的示例https://makingsoftware.wordpress.com/2013/02/16/using-git-subtrees-for-repository-分离/ I followed that article and it worked totally fine for me. 我遵循了那篇文章,对我来说效果很好。

暂无
暂无

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

相关问题 更加聪明的git filter-branch --subdirectory-filter - More clever git filter-branch --subdirectory-filter 与`git filter-branch --subdirectory-filter`相反的是什么? - What is the opposite of `git filter-branch --subdirectory-filter`? 在 git filter-branch --subdirectory-filter 之后保留 stash - Keep stash after git filter-branch --subdirectory-filter git filter-branch subdirectory-filter & git subtree split -P 的区别 - Difference between git filter-branch subdirectory-filter & git subtree split -P git filter-branch --subdirectory-filter失败,并显示“文件编号错误-无法获取提交” - git filter-branch --subdirectory-filter fails with “Bad file number - could not get commits” 运行git filter-branch子目录-filter也可以删除其他子目录的历史记录 - Running git filter-branch subdirectory-filter to also remove get rid of other subdirectories history 使用git filter-branch --subdirectory-filter保留--no-ff merge提交 - Preserve --no-ff merge commits with git filter-branch --subdirectory-filter 未知 object 类型 0 在偏移量 - 所有 repo 镜像损坏,防止过滤器分支子目录过滤器 - unknown object type 0 at offset - all repo mirrors corrupted preventing filter-branch subdirectory-filter 使用git filter-branch --subdirectory-filter后,如何仍使用旧的repo并回收git空间? - After using git filter-branch --subdirectory-filter how do I still use old repo and reclaim git space? 筛选器分支后更新git子目录 - Update git subdirectory after filter-branch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM