1

I have successfully split a previous commit deadbeef using git rebase -i deadbeef~1 as suggested in this question. I did this on my development branch.

As far as i can tell everything is fine, deadbeef is gone from the history of development and has been replaced by the commits i did while rebasing.

Two questions arise now:

  1. I have several branches that have deadbeef in their history - how do i "merge" the rebase into those branches? What would happen if i did a git merge development in any of those branches?
  2. deadbeef has also been pushed to a remote repository and is present on a few other clones. To make sure deadbeefis really gone from all the history, i will have to push --force and do a new clone on all other development machines, right? (Luckily, this is rather easy, i have access to all other clones).

Thanks!

Community
  • 1
  • 1
Pontomedon
  • 937
  • 9
  • 18

1 Answers1

1

1) You will have to rebase other branches too. Most probably

git checkout other-branch
git rebase development

will do the trick.

Update: as we worked out in comments, you could do

git rebase -i development

and delete the deadbeef from the list of commits to rebase. After that the rest of the commits will apply cleanly.

1b) There is another alternative to doing that, more manual. Take a branch with a deadbeef that you want to redact, say it's foobar. Create a new tmp branch, starting from commit immediately preceding the deadbeef. Then cherry-pick commits which you split deadbeef into (from development). Then cherry-pick all the commits from the deadbeef (not including) to the end of the branch (from foobar). Check that tmp is correct and rename it to foobar.

2) Yes you will have to push -f and re-create or reset the branches on other development machines. You will probably just have to do (on other machines)

git fetch
git checkout development
git reset --hard origin/development
squadette
  • 8,177
  • 4
  • 28
  • 39
  • unfortunately `git rebase development` does not do the trick, it prints `First, rewinding head to replay your work on top of it... Applying: - ` and errors out with tons of merge conflicts. i guess this is because it notices that deadbeef is missing from `development`, right? – Pontomedon Aug 03 '14 at 15:19
  • Take a look at those merge conflicts — they shouldn't be too hard to fix actually. Fix them, `git add ...` and say `git rebase --continue`. – squadette Aug 03 '14 at 15:23
  • Ok, I've described another method, please see updated text of the answer. – squadette Aug 03 '14 at 15:28
  • actually, the merge conflicts are very easy to fix, but i discovered a better way (since there are LOTS of them, `deadbeef` was a huge commit): I ran `git rebase -i development` and removed `deadbeef` from the buffer. All other commits (which were exactly those that were in `other-branch`, but not in development) rebased fine. – Pontomedon Aug 03 '14 at 15:28
  • great! I'll remember this idea. However, if your splitted commits are textually equivalent to the deadbeef, then the rebase magic should have worked by itself. But yes, probably it's simpler not to let it kick in in the first place. – squadette Aug 03 '14 at 15:29
  • yes, the commits i've replaced `deadbeef` with produce (together) the exact same diff as `deadbeef` did. I was very careful to make sure this is the case :). You could update your answer, I'll accept it then! – Pontomedon Aug 03 '14 at 15:31