简体   繁体   English

如何在git修订树的第一次提交中添加新的基础

[英]How to add a new base to the first commit of a git revision tree

I have setup a git repository for some days. 我已经设置了几天的git存储库。 Now I found my start point is some work based on an original release. 现在我发现我的起点是基于原始版本的一些工作。 I hope to add the original release as the first commit and all the my current commit tree is based on it. 我希望将原始版本添加为第一个提交,并且我当前的所有提交树都基于它。 Is it possible? 可能吗? The current git revision: 目前的git修订版:

A---B---C---D master A --- B --- C --- D大师

I hope to insert one commit at the beginning 我希望在开头插入一个提交

O---A---B---C---D master, so that I could use rebase to generate such branch O --- A --- B --- C --- D高手,这样我就可以用rebase来生成这样的分支

O---A---B---C---D master O --- A --- B --- C --- D大师
\\---D' my_rebase_branch \\ --- D'my_rebase_branch

Maybe you could try it as below: 也许你可以尝试如下:
1. create a new branch called base_work for the original release branch 1.为原始版本分支创建一个名为base_work的新分支
2. create a new branch called others_work for your start point 2.为您的起点创建一个名为others_work的新分支
3. suppose your current work branch is my_work. 3.假设您当前的工作分支是my_work。 Try the following command: 请尝试以下命令:

git rebase --onto base_work others_work my_work

The command will let your work based on base_work, instead of others_work. 该命令将使您的工作基于base_work,而不是others_work。

If you want to recreate your commits on top of existing commits of an existing repo, you would need to import that repo first before the rebase: 如果要在现有仓库的现有提交之上重新创建提交,则需要先在rebase之前导入该仓库:

cd /path/to/your/repo
git remote add original /url/original/repo
git fetch original

Then you can rebase, using the --root option : 然后你可以使用--root选项进行rebase:

git checkout master
git rebase --onto original/master --root master

If " original " does not exist, you can create it as long as you have access to the content (source code) of said release: 如果“ original ”不存在,只要您可以访问所述版本的内容(源代码),就可以创建它:

cd /path/to/original/source/code/of/release
git init .
git add .
git commit -m "original release source code"

Then, go back to your own repo, and repeat the command I mentioned (no need for rebase --onto here) 然后,回到你自己的回购,并重复我提到的命令(不需要rebase --onto在这里)

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

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