2

I have been trying different approaches of git rebase -i --root, but they don't seem to do the trick for me.

I have this commit tree:

0 -> 1 -> ... -> 2 -> 3 -> 4 -> 5 -> 9 ...
                            \
                             -> 6 -> 7 ...
                                 \
                                  -> 8 ...

and I want to wind up with this:

3 -> 4 -> 5 -> 9 ...
      \
       -> 6 -> 7 ...
           \
            -> 8 ...

which is squashing/deleting the first n (which may be hundreds) of commits. The repository has not been pushed anywhere yet.

After trying different kinds of rebases (mainly setting 0 to pick and 1-3 to fixup), most of them result in this:

0 -> 1 -> ... -> 2 -> 3 -> 4 -> 5 -> 9 ...
0 -> 1 -> ... -> 2 -> 3 -> 4 -> 6 -> 7 ...

which are completely unrelated to each other and not what I want.

I have tried VonC's approach to the letter but I am obviously missing something.

EDITED

If anyone wants to try out their approach, I have set up a mock repository here: https://github.com/dr01g/gitr-root-rebase.git

Community
  • 1
  • 1
Daniel
  • 4,033
  • 4
  • 24
  • 33
  • What command are you typing? Do you use the `rebase -p` (preserve-merge) option? (https://www.google.com/search?q=git+rebase+preserve+merge&ie=utf-8&oe=utf-8) – VonC Mar 09 '16 at 06:52
  • No, I have tried `git rebase -i --root` with various combinations of pick/squash/fixup and the approach mentioned by [Charles Bailey](http://stackoverflow.com/questions/435646/combine-the-first-two-commits-of-a-git-repository/436530#436530). I have not tried the `-p` option. Yet. – Daniel Mar 09 '16 at 07:54
  • I would highly suggest to add a -p in there, in order to not end up with different histories (since the old commits before rebase would still be referenced by the branches in their merge commit) – VonC Mar 09 '16 at 07:55
  • @VonC It worked better for `master`, but it still ripped out the other branch so I that the branches are linear and have no common parent. – Daniel Mar 09 '16 at 08:05
  • Are you talking about branch with commit 8? Is at least thebranh with commit 7 well preserved? – VonC Mar 09 '16 at 08:42
  • I have set up a mock repo locally to experiment on that looks like the one above, but simplified and with only one branch off `master`. So in that case it would be the branch with commit 6 and 7. I'd be happy to make it publicly available if it's easier for everyone involved. – Daniel Mar 09 '16 at 08:48
  • "So in that case it would be the branch with commit 6 and 7": do you mean 6 and are correctly preserved? And that commit 8 is not, and still references the old pre-rebase commits? – VonC Mar 09 '16 at 08:50
  • No, I get two entirely separate "trees" (more like straight lines) With `01 (fixup) -> 2 -> 3 -> 4 -> 5 -> 9` and `0 -> 1 -> 2 -> 3 -> 4 -> 6 -> 7`. The _contents_ are correct in both branches, but the ancestry is shot to Hades. – Daniel Mar 09 '16 at 08:59
  • That's strange: the -p should have at least preserved the 6-7 branch. – VonC Mar 09 '16 at 09:01
  • Unrelated: I just saw the edit that you did on https://stackoverflow.com/posts/49775123/revisions ... and I am kinda wondering: what is the point of your edit? Especially: it is considered *good practice* to not have such salutation as "Kindly help me to fix this." That sentence is not contributing *any* value to the question. So why did you invest energy to bring it **back**? – GhostCat Apr 11 '18 at 13:17
  • @GhostCat Sorry, my apologies. That trailing comment should indeed be removed. I was focusing on getting the code correctly formatted and indented. I guess it just slipped by since I clicked "Improve edit" I assumed that my edit would be done on top of yours, where it already was removed. I have fixed it now. Shall we remove these comments while we are at it? Thanks for bringing it to my attention. – Daniel Apr 11 '18 at 13:30
  • Does this answer your question? [Combine the first two commits of a Git repository?](https://stackoverflow.com/questions/435646/combine-the-first-two-commits-of-a-git-repository) – Guildenstern Apr 30 '23 at 12:29
  • @Guildenstern Close enough! I had to manually reapply the branches with a combination of rebasing and cherry-picking but ultimately I got it the way I initially wanted. Thanks a lot! – Daniel May 01 '23 at 17:44

0 Answers0