我可以在现有提交下面进行git提交而不在下一次提交中保留任何内容吗?(只是为了将代码载入历史)



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

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

历史现在的样子:

  1. 添加自述
  2. 添加新来源
  3. 更改1
  4. 更改2

我希望它看起来像什么:

  1. 添加自述
  2. 添加旧源
  3. 添加新来源
  4. 更改1
  5. 更改2

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

这甚至可以在不需要重建整个回购的情况下实现吗?

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

好的。。。。这样做:

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

你完成了

最新更新