Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
764 views
in Technique[技术] by (71.8m points)

git - setting a commit's parent without rebase

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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..

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...