git - 设置提交的父级而不进行变基
我使用 git-svn 创建 SVN 存储库的 git 镜像。 SVN 内部的结构有点不标准,因此 git 创建了一个与 master
分支没有共同提交的分支。
A---B---C topic
D---E---F---G master
我知道提交 A
是基于提交 E
并且我非常肯定我已经解决了导致 git 无法识别这一事实的问题(使用 filter -分支
)。我想要做的是将 topic
重新附加到 master
分支,将 E
设置为 A
的父级:
A---B---C topic
/
D---E---F---G master
git-rebase 似乎对我不起作用,因为提交 A
的差异列出了 master< 中已存在的大量文件的创建/code>,导致大量冲突。
根据我对 git 的理解,只需将 E
设置为 A
的父级就足以解决所有问题。
这可能吗?如果是的话我该怎么办?
I used git-svn
to create a git mirror of an SVN repository. The structure inside the SVN was a little off-standard, so git created a branch that has no common commit with the master
branch.
A---B---C topic
D---E---F---G master
I know that commit A
is based off commit E
and I'm pretty positive that I've fixed the issues causing git not to recognize that fact (using filter-branch
). What I want to do is re-attach topic
to the master
branch, setting E
as the parent of A
:
A---B---C topic
/
D---E---F---G master
git-rebase
doesn't seem to work for me because the diff for commit A
lists the creation of a whole lot of files that already exist in master
, resulting in a huge number of conflicts.
From my understanding of git just setting E
as the parent of A
should be enough to solve all problems.
Is this possible? If it is, how can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看一下移植(移植文件可以在
.git/info/grafts
中找到)。格式非常简单:这使 git 相信提交具有与实际不同的父级。
在较新版本的 Git 中,您需要使用 替换机制将历史移植到一起:
git Replace --graft ...
无论选择哪种方法(移植文件或替换引用),都使用过滤器分支使移植永久化(因此可以删除移植文件):
请注意这重写存储库的历史记录,因此不应在共享存储库上使用!
例如,如果您只想重写正在嫁接到 master 分支上的提交的历史记录,请使用以下命令:
Have a look at grafts (the graft file can be found in
.git/info/grafts
). The format is pretty simple:This makes git believe that a commit has different parents than it actually has.
In newer versions of Git, you want to use the replace mechanism to graft histories together:
git replace --graft …
Regardless of chosen approach (graft file or replace refs), use filter-branch to make grafts permanent (so the grafts file can be removed):
Note that this rewrites history of the repository, so should not be used on shared repos!
If you only want to rewrite the history of the commits that are being grafted onto the master branch, for example, use this command:
根据你的图表(尽管我担心你所说的“我非常肯定我已经解决了导致 git 无法识别这一事实的问题(使用
filter-branch
”)的含义。 ),您应该能够执行以下操作。Based on your diagrams (although I'm concerned about what you mean by "I'm pretty positive that I've fixed the issues causing git not to recognize that fact (using
filter-branch
)."), you should be able to do something like the following.您所需要的只是:
root 选项允许您包含 A。
更新:
如果您想保留要变基的部分的分支和合并,请添加
--preserve-merges
选项。All you need is this:
the root option lets you include A.
UPDATE:
Add the
--preserve-merges
option if you want to retain the branching and merging of the part that you are rebasing.