Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Rewriting old commits in the master branch

Say I have this commit history:

A - B - C (master)
         \
          D - E - F (Feature)

I’d like to amend commit B. So, I do:

  • git checkout master
  • git rebase -i <hash of A>

After the rebase is done, I see the change using git log.
However when I switch to the Feature branch, commit B is still as it was before the rebase.
In other words, when I’m in master branch, the commit history looks like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

A - B' - C (master)

When I switch to Feature branch, the commit history looks like this:

A - B - C (master)
         \
          D - E - F (Feature)

I understand that rewriting the commit history is not wise, but I have to do this in my case.

How can I amend an old commit and have those changes be reflected on every branch?
Am I doing this the wrong way?

The new commit history will be force pushed into Github and I don’t want to mess things up.

Any help would be appreciated.

>Solution :

After your rebase, what you actually have is

  B'- C' (master)
 /
A - B - C
         \
          D - E - F (Feature)

So now to complete the operation you’d have to rebase Feature on (the recently rewritten) master

$ git checkout Feature

$ git rebase master

          D'-E'-F' (Feature)
         /
A - B'- C' (master)
 \       
  B - C - D - E - F (soon to be garbage collected)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading