0

Suppose, I have two branches C and A, where A was made with C as base.

Given some time, C and A will be having different commits based on the features implemented and bugs fixed in both.

Now, suppose I just needed the commits of C in A. For this I did:

  • Made a new branch B with C as the base branch.
  • Created a pull request with A as base and compared it with B.
  • Now I see commits and changes from C which were not there in A and so I happily merged the PR after some approvals.

After the PR is merged, I see A has all the changes of C but wait, C has all the changes of A as well. I just wanted to know in what all scenarios can this happen and well, how I can avoid it?

If this was not the right way to bring changes from C to A, please let me know the right way of doing it.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
OV3RKILL
  • 25
  • 8
  • 1
    When the PR was merged, _how_ was it merged? – evolutionxbox Sep 23 '22 at 16:09
  • PR was merged using the Github website. Creation of branch as well as all other stuff took place in the website as well. Sorry, but I didn't understand the 'when' part of your question. – OV3RKILL Sep 23 '22 at 16:23
  • _"PR was merged using the Github website"_ - sure I get this, but how was it merged? Was it a rebase, merge commit, or something else? – evolutionxbox Sep 23 '22 at 16:24
  • It was a merge commit. – OV3RKILL Sep 23 '22 at 16:27
  • If you made a PR of `A` against `B`, since `B` contains `C`'s commits, when the PR is completed `A` will also contain them. – evolutionxbox Sep 23 '22 at 16:31
  • Yes, that was intended and I needed the commits of `C` in `A`. But eventhough it happened as intended, after completing the PR, I noticed `C` also has the commits of `A`, which is the issue here. – OV3RKILL Sep 23 '22 at 16:36
  • I suggest you look at the commit tree to understand why. Remember, branches are only a label which point to _one commit_, and they move. – evolutionxbox Sep 23 '22 at 16:39
  • Thanks for the suggestion and your time, I will try looking at the commit tree and see what might have gone wrong. – OV3RKILL Sep 23 '22 at 16:45
  • It's not a matter of something going wrong. You probably need to learn a bit more about how git works, what branches are, how commits link to each other, and how merging works. – evolutionxbox Sep 23 '22 at 16:47
  • Yes, definitely, there is a lot to learn here and understanding this incident will help me understand git more. – OV3RKILL Sep 23 '22 at 16:53
  • @JishnuRaj Maybe you accidentially based B on A (or another branch) instead of C? – Jay Sep 23 '22 at 16:55
  • 1
    @Jay I can assure you that B was made out of C and I also checked if that was the case afterwards. Moreover if B was based out of A, then it should just show me, there are no changes right? Regardless, there are no branches other than A, B and C in this scenario. Thanks for looking into my dilemma. – OV3RKILL Sep 23 '22 at 17:51

0 Answers0