git - setting a commit's parent without rebase

江枫思渺然 提交于 2019-11-28 04:33:01
knittl

Have a look at grafts (the graft file can be found in .git/info/grafts). The format is pretty simple:

<commit sha1> <parent1 sha1> <parent2 sha1> … <parentN sha1>

This makes git believe that a commit has different parents than it actually has. Use filter-branch to make grafts permanent (so the grafts file can be removed):

git filter-branch --tag-name-filter cat -- --all

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 --tag-name-filter cat -- master..

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.

# checkout A
git checkout A

# Reset the branch pointer to E so that E is the parent of the next commit
# --soft ensures that the index stays the same
git reset --soft E

# Remake the commit with the E as the parent, re-using the old commit metadata
git commit -C HEAD@{1}

# Rebase the topic branch onto the modified A commit (current HEAD)
git rebase --onto HEAD A topic

All you need is this:

git rebase --root --onto master^^ topic^^ topic

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!