Sublime Forum

Editing commit duplicates all following commits in all future branches

#1

I am not sure if this is a bug, or if it is by design and it’s just my limited knowledge of Git that gets me confused…

Say I have a branch with multiple commits, and another branch that splits off halfway:

A - B - C - D - E - F
              \ G - H

Now if I edit commit “C” (Context menu > Edit Commit > Edit Commit Contents), then I end up with the following tree:

A - B - C' - D' - E' - F'
      \ C - D - G - H

(Where C’, D’, etc contain the edit I did.)

Is this by design, or is there a bug?

0 Likes

#2

This is a Git thing, not specific to Sublime Merge. You can, if you wish, subsequently rebase G onto D' to give you a G' - H' branch off of D'. The reason this doesn’t happen automatically is that if anyone else is using G or H, you are cutting their knees out from under them.

Here’s the CLI instructions for doing what I described. (Sorry I don’t know how to do it in SM)

0 Likes

#3

Thanks, that makes sense!

I haven’t figured out how to do a rebase on any random commit in Sublime Merge yet (as per your "rebase G onto D'"), I’ve only been able to rebase onto the top of a branch (which would be F' in my example).

0 Likes

#4

To do arbitrary sequences of commits, you need the 3-term rebase --onto. From this tree:

A - B - C' - D' - E' - F'
      \ C - D - G - H

into this tree:

A - B - C' - D' - E' - F'
                \ G' - H'

You’re going to do

git rebase --onto "D'" D H

Or, if it is helpful:

git rebase --onto desired-branch-point first-commit^ last-commit

Note the ^! It is critical. Also, if you use a branch reference for the last-commit, it will move the branch with the rebase. If you use the SHA hash, the branch will stay pointing at its old place.

0 Likes