简体   繁体   English

如何将master分支历史记录重写为其他Repository master分支

[英]How to rewrite the master branch history to other Repository master branch

Is there any way or any tool or commands to re write the history of master or some A branch from some commit number to newly created master branch of NEW REPOSITORY with master branch with 0 commits or no history. 是否有任何方式或工具或命令来重新书写的历史master或一些A分支从一些承诺数新创建的master 新的存储库的分支与master分支0提交或没有历史。

In such a way that : 以这种方式:

  1. All the previous commits before commit number "45678" should be re written as single commit in the new repository master branch 提交号“ 45678”之前的所有先前提交均应在新的存储库主分支中重写为单个提交
  2. Rewriting the history should begin from commit "45678" 重写历史记录应从提交“ 45678”开始

Thanks 谢谢

(I don't have a suitable sacrificial repository to test this: you've been warned). (我没有合适的牺牲品库来测试这一点:已警告您)。

I would think merge --squash could do this. 我认为merge --squash可以做到这一点。

  • Add new repository as remote 将新存储库添加为远程存储库
  • Create dest branch, push branch with upstream tracking to the new repository 创建目标分支,将具有上游跟踪的分支推送到新存储库
  • Checkout the new branch 结帐新分支
  • Merge --squash from your source branch 从源分支Merge --squash
  • Commit 承诺
  • Push to the new repository 推送到新的存储库

(See this answer as well.) (也请参阅此答案 。)

Old Content (before question edit) 旧内容(问题编辑之前)

Just create the new repository as a new remote on your clone of the original repository; 只需在原始存储库的克隆上将新存储库创建为新的远程目录即可; and then push to the new repository. 然后推送到新的存储库。

git remote add newrep url-to-new-repository
git push -u newrep master

Repeat the last command for each branch you want to push. 对要推送的每个分支重复最后一个命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM