问题描述
我有一个分支testing
,其中包含对a/
中的文件以及b/
中的文件的大量更改。
我想将所有来自testing
的提交移植到我的master
分支上。但是,我只想将更改移植到a/
。在master
分支上,b/
在.gitignore
中,并且不应显示在历史记录中。
我想以一种保留提交消息,作者身份以及理想的时间戳的方式来做到这一点。
我相信git filter-branch
或其推荐的替代词git filter-repo
可能是解决此问题的正确工具。但是,它们似乎针对整个存储库操作,而不是在分支之间移植,因此弄清楚如何将它们用于我的目的使我进入StackOverflow。
解决方法
事实证明,使用git filter-repo
非常简单:我只需要使用--refs
选项。
我从testing2
创建了一个新分支testing
:
git checkout testing
git checkout -b testing2
然后跑
git filter-repo --invert-paths --path b/ --refs testing2
然后,我将新重写的testing2
合并到master上:
git checkout master
git merge testing2