【问题标题】:Add missing git history添加缺少的 git 历史记录
【发布时间】:2016-09-20 11:00:00
【问题描述】:

我通过将所有文件从 A 添加到 B 错误地将 GitHub 存储库 (A) 移动到新的 Bitbucket 存储库 (B),这丢失了所有历史记录。我在 B 上做了一些工作(多次提交)并意识到了我的错误,所以现在 A 包含直到某个点的旧历史,而 B 包含从那个点开始的新历史。如何将 A 的历史记录与 B 合并,以便 B 包含文件的完整历史记录?

P.S.:我猜主要问题是 B 上的第一次提交与 a 上的第一次提交不同,因为它没有历史记录,它包含每个文件的全文。

示例

存储库 A

Commit 1: Create new File X
Commit 2: File X
+ Hello World
Commit 3: File X
+ This is a test

存储库 B

Commit 1: Create new File X:
+ Hello World
+ This is a Test
Commit 2
+ This is a new line

我想创建一个具有以下历史记录的新存储库 C:

Commit 1: Create new File X
Commit 2: File X
+ Hello World
Commit 3: File X
+ This is a test
Commit 4:
+ This is a new line

【问题讨论】:

  • 您应该能够在存储库 B 中运行 git format-patch <first-commit-in-B>..<tip-of-B>,然后使用 git-am 将生成的一系列补丁应用到 A。
  • 或者,将 B 作为远程添加到 A,获取,然后挑选除第一个提交之外的所有内容。 (这两种方法都假设 B 中的第一次提交与 A 中的最后一次提交的状态相匹配。)
  • @SvenMarnach 格式补丁和 git 运行良好,谢谢!你能从评论中回答吗?

标签: git git-rewrite-history


【解决方案1】:
git init c
cd c
git remote add a ...
git remote add b ...
git branch -u a master
git pull
git checkout b/master -b new-master
git rebase master

也可能有助于首先从新主服务器中删除初始文件添加;或者它可能只会让它变得更加困难,现在不确定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-15
    • 2019-01-07
    • 2023-01-07
    • 2020-05-17
    相关资源
    最近更新 更多