2

I have two branches 'master' & 'child'.

  • I added a commit on the child branch and merged it onto the master branch.
  • I reverted this commit on the master branch(and also on the child branch separately).
  • I added the same changes from the first commit on the child branch(kind of like revert of revert, but added as a new change via new commit).
  • When I try to merge child onto the master now, it is not taking in those changes.

Is this how git is supposed to work?

Created a test repo and replicated this for reference. master (https://github.com/ashok-r/test_repo/tree/master), child (https://github.com/ashok-r/test_repo/tree/child)

Bit of a background as to how we ran into this problem. We use 'master' branch as a stable branch and other branches for development. We had to revert a commit(Let's call the changes 'A'). Instead of doing it on development branch and bringing it onto master, we reverted on the master branch itself. After a few days, we added a new commit on the development branch which includes those reverted changes('A') along with some other changes('B'). When we merge this onto master, only the new changes('B') gets added and the previously reverted changes('A') are ignored. Is this the expected behaviour? It looks strange to see some changes from a commit gets added while some changes are ignored.

I know its not ideal scenario to commit/revert directly on the stable branch, but if we did, those exact changes can't be brought back via another branch?

1 Answers1

0

Yes this is how it supposed to work. I wrote a short blog post on a similar case which explains why it works that way. You can read it here https://adventuresinscm.wordpress.com/2019/08/25/merge-from-master-overrides-a-revert-commit/

In short, Git performs a 3-way merge based on a common ancestor (in your example it's fc82cf72). It consideres the difference between master to the CA and between the child to the CA. In your case, there is no change between the tip of the child branch (184d08c0) to the CA, so from Git's point of view you are merging a branch with no changes, so it skips it and leaves the content of master as it was before the merge.

yossiz74
  • 889
  • 1
  • 9
  • 16