0

我曾经和我的团队一起做一个项目,我们在迁移到 git 之前使用 svn 进行版本控制,现在 svn 的历史早已不复存在。我有我们开始使用的原始资源,我希望它出现在 git 历史记录中,这样我就可以看到我们从 git 或 IDE 所做的更改。

为了能够做到这一点,我必须能够将原始资源放在现有提交之下而不保留任何内容。

现在的历史是怎样的:

  1. 添加自述文件
  2. 添加新来源
  3. 改变 1
  4. 改变 2
  5. ...

我希望它看起来如何:

  1. 添加自述文件
  2. 添加旧资源
  3. 添加新来源
  4. 改变 1
  5. 改变 2
  6. ...

我们还删除或重命名了许多文件,我不希望它们属于存储库的当前状态。我能做的最好的事情是检查新分支上的自述文件提交,将旧源放在它上面,然后使用他们的策略将 master 合并到分支中以覆盖文件。我可以将旧源视为第二次提交,然后在最后一次更改之上进行合并提交。它保留已删除或重命名的文件,并且不显示现有文件的历史记录。

这甚至可以在不必重建整个回购的情况下完成吗?

4

1 回答 1

1

我没有完全得到你想要的......但如果我理解正确,你想在新来源之前添加旧来源......并且你在旧来源和新来源之间移动了很多文件,对吧?

好的....这样做:

git checkout -b temp revision1
// put the _old_ sources here
git add .
git commit -m "Old sources"
git checkout revision2 # where you have the new sources
git reset --soft temp # set the branch pointer in "old sources keep all files the way they are, everything that changed will be in index... even moved files
git commit -m "new sources¨
# let's move temp branch's pointer
git branch -f temp
git checkout temp
# now we replicate the other changes from master (master, right?)
git cherry-pick revision2..master
# if you like the result
git branch -f master # set master over here
git checkout master
git branch -d temp

你完成了

于 2020-04-21T19:53:30.560 回答