git - 按文件拆分每个提交?

标签 git

我为我的项目积累了大量的 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 过滤分支


示例

// 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/

相关文章:

git - 查看谁删除了 git 标签

git - 如何缩短 'git pull' 命令的输出?

Github:只读访问私有(private)仓库

c - 为每个平台维护一个单独的分支

android - 从 Eclipse 恢复已删除的 Git 存储库

git - bin 和 obj 目录不能被忽略。也推不了

Git & 安卓工作室 : Change the details of submitted change list

git - 从 Heroku 应用程序中删除文件

git - 无法推送到 github,openssl 问题

git - git中未删除本地分支