我为我的项目积累了大量的 git 提交。作为清理存储库的第一步,我想将每个 提交分成两个提交:一个只涉及特定文件/some/directory/file,另一个涉及其他所有内容。
由于 git 历史相当长,我想避免手动执行此操作。
我考虑过(但还没有真正尝试过)的一些方法是:
- 使用
git rebase --exec
和执行拆分的脚本。 - 使用
filter-branch
。 (对这个工具不是很熟悉)
但是,由于这在我看来是一个相当普遍的问题,所以我想在尝试重新发明轮子之前先检查一下这里。有什么自动化的方法可以做到这一点吗?
最佳答案
你在路上,你尝试过的就是方法。
正如您所发现的,您有 2 个主要选择:
git rebase -i
又名:squash
(手动程序)
// Manipulate any commit by editing it and commitign again
git rebase -i HEAD~X
Since the git history is fairly long, I'd like to avoid doing this manually.
git 过滤分支
阅读这篇解决您问题的文章 How to tear apart a repository: the Git way
git filter-branch
将在条件中指定的每个提交上运行,然后你可以用它做任何你想做的事(通过脚本)而不是手动。Here是另一篇关于
的非常有用的文章filter-branch
示例
// Remove any given file from commits
// Now you can commit it again into a new commit
git filter-branch --tree-filter 'rm -f <file name> HEAD
关于git - 按文件拆分每个提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34556545/