rebase - Git change parent commit rev -
a colleague of mine checked out commit correct_parent, made changes based on correct_parent, , somehow mistakenly committed wrong parent commit rev wrong_parent instead of correct_parent (i'm not sure how managed that). let's call commit bad_commit.
a whole bunch of new commits based on bad_commit, including new merge commits, it's not linear structure, more diamonds. being merged single branch again. let's call bad_branch.
i want recreate bad_commit correct parent commit correct_parent, , follow-up commits well.
i'm not sure how that. somehow git rebase , --strategy ours or so. note not rebase because diff between wrong_parent , bad_commit not sense-full, don't want apply patch.
a picture:
wrong_parent -> bad_commit (based on correct_parent) -> ...... -> bad_branch head i want:
correct_parent -> bad_commit (merge strategy: take bad_commit) -> .... -> fixed_branch
this can fixed graft file, made permanent using git filter-branch.
to set bad repo:
git init echo > file && git add file && git commit -m "good parent" echo b > file && git add file && git commit -m "bad parent" echo c > file && git add file && git commit -m "child" file and appears in git log --oneline as
f6e3133 child 4dc60b6 bad parent 7b5da8a parent
now pretend "good parent" parent of "child":
echo `git rev-parse @ @~2` > .git/info/grafts and check git log --oneline again:
f6e3133 child 7b5da8a parent
now make permanent:
git filter-branch and check git log --oneline third time:
87b8fc8 child 7b5da8a parent
you see child got new hash. that's because commit re-written proper parent. parent didn't new hash, because unchanged. children of "child" have been rewritten well.
finally, clean up:
rm .git/info/grafts
Comments
Post a Comment