除去文件的所有提交(特定列表除外)

时间:2018-08-23 22:38:49

标签: git

我有repo1和repo2。我想将一些文件从repo1移植到repo2(它们的相对路径将需要在repo中更新,但这可以是一个单独的步骤)。

我尝试过:

  1. 删除所有文件的历史记录,但repo1中所需的文件除外

    git filter-branch --prune-empty --index-filter 'git rm -r --cached * && git reset $GIT_COMMIT -- file1 file2 file3

  2. 在repo2中,git add remote repo1 ../repo1/relative/address到repo1

  3. git fetch repo1 && git merge repo1/master --allow-unrelated-histories
  4. git mv将文件移动到repo2中的适当位置

主要起作用,但是filter-branch命令未删除合并提交。我能够使用git rebase <some early commit before all the Merge commits>删除Merge提交,但是提交者更改为我的用户:(

我可以使用filter-branch进行其他操作来保留历史记录并删除合并提交吗?


过去我曾经使用过:

git filter-branch --prune-empty --index-filter 'git rm --cached --ignore-unmatch file1'

这使我可以删除仅涉及某些file1的提交,但是在这里我想反过来,因为遍历此存储库中的每个文件都不现实。

我也尝试过:

git filter-branch -f --prune-empty --env-filter '                               
export GIT_COMMITTER_NAME="$GIT_COMMITTER_NAME"
export GIT_COMMITTER_EMAIL="$GIT_COMMITTER_EMAIL"
export GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME"
export GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL"
' --tag-name-filter cat -- --all

作为一个扩展目标,我还想保留CommitDate,但这不是必需的,因为AuthorDate仍会存在。

0 个答案:

没有答案
相关问题