“我是否应该创建一个新的空白项目并依次添加旧的
项目,然后在其上重播当前存储库?”
是的。
假设“前历史”干净地合并到现有历史中,您可以使用两个 git 命令将这两个历史嫁接在一起。在您的新 git 存储库中,运行以下命令:
git --git-dir=/path/to/original/.git log -m -p --reverse --first-parent --binary --pretty=email | git am --keep-non-patch --whitespace=fix
这有点难看,所以在这里它的格式很奇怪但很明显(只要你复制和粘贴一体机,它仍然可以运行):
git --git-dir=/path/to/original/.git \
log -m -p --reverse --first-parent --binary --pretty=email |
git am --keep-non-patch --whitespace=fix
之后运行“git log”命令以确保一切正确。一旦您感到满意,我建议您删除或重命名现有的 bitbucket 存储库,然后将其推送到它的位置。
Caveat #1:“git log --first-parent”从历史中删除所有分支并合并,因此结果只是一个单一的线性提交序列。 (有关 --first-parent 的更多信息:GIT: How can I prevent foxtrot merges in my 'master' branch? 和 https://bit-booster.blogspot.ca/2016/02/no-foxtrots-allowed.html)。
警告 #2:“git am”讨厌空提交(例如,git commit --allow-empty),因此如果您有其中任何一个,则必须将过程分为三个步骤:1. git 日志 > git_am.log。 2.从“git_am.log”中删除空补丁。 3. 猫 git_am.log |混帐我
以下是关于上面使用的“git log”选项的一些说明:
-m
Include patches caused by merge commits.
-p
Show patches in the "git log" output.
--reverse
Reverse "git log" ordering (since we want oldest-to-newest).
--first-parent
Only include 1st parent of merge commits.
--binary
Include binary-diffs in output.
--pretty=email
Have "git log" output its data in the "email" format
that "git am" is expecting.
我将查找“git am”选项作为读者的练习(例如,“git help am”)。