Pontomedon
Pontomedon

Reputation: 947

GIT: How to merge split commit into different branch

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!

Upvotes: 1

Views: 240

Answers (1)

squadette
squadette

Reputation: 8286

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

Upvotes: 1

Related Questions