0

I've two branches feature and development and for the sake of simplicity, assuming that both the branches have only one file, say test.py

In feature branch,test.py is as follows

--few lines ---
renewal_id = models.IntegerField(null = True)
renewal_counter = models.IntegerField(null = True)

In development branch,test.py is as follows

--few lines ---
renewal_id = models.IntegerField(null = True)
cancelled_amount = models.IntegerField(null = True)
cancelled_amount_tax = models.IntegerField(null = True)
cancelled_by = models.CharField(null = True)

For merging, I'm creating a new branch called temporary_branch_for_merging from feature and merging the development into the new branch but it auto resolves instead of showing merge conflict

git checkout feature
git branch -b temporary_branch_for_merging
git merge development

I'm expecting it to show my a conflict as but the file gets auto-merged and the final result looks like this:

--few lines ---
renewal_id = models.IntegerField(null = True)
cancelled_amount = models.IntegerField(null = True)
cancelled_amount_tax = models.IntegerField(null = True)
cancelled_by = models.CharField(null = True)
 

what I want the final output to be like :

--few lines ---
renewal_id = models.IntegerField(null = True)
renewal_counter = models.IntegerField(null = True) <<< this line to get added after the merge
cancelled_amount = models.IntegerField(null = True)
cancelled_amount_tax = models.IntegerField(null = True)
cancelled_by = models.CharField(null = True)

on doing git diff my_hash:test.py HEAD:test.py in temporary_branch_for_merging i get something like :

  --few lines ---
  renewal_id = models.IntegerField(null = True)
- renewal_counter = models.IntegerField(null = True)
+ cancelled_amount = models.IntegerField(null = True)
+ cancelled_amount_tax = models.IntegerField(null = True)
+ cancelled_by = models.CharField(null = True)
Irfan Harun
  • 979
  • 2
  • 16
  • 37
  • What's the content of that file in the merge base commit? – torek Oct 01 '20 at 09:13
  • since the `temporary_branch_for_merging` branch is being created from 'feature' branch. the contents of file when merging will be same as mentioned in `feature` branch – Irfan Harun Oct 01 '20 at 09:31
  • I think you mean `git checkout -b`? And what's `temporary_branch_for_merging` for? – Schwern Oct 01 '20 at 09:50
  • Could you show us the relevant parts of `git log --graph --decorate --oneline --all` please? – Schwern Oct 01 '20 at 09:55
  • I'm with @torek. What does the file look at about those lines in thr last revision that is present on both branches? (Assuming they diverged) – eftshift0 Oct 01 '20 at 10:03
  • Assuming you're really running `git branch -b temporary_branch_for_merging`, that's basically not doing anything at all. If you're doing `git checkout -b` rather than `git branch -b`, we still need to know which commit is the merge base and what's in that file. Run `git merge-base --all development` just before running `git merge`, then use `git show :test.py` to view the merge base version of the file. Or, run `git diff :test.py HEAD:test.py` and `git diff :test.py development:test.py` before merging. – torek Oct 01 '20 at 10:33
  • @Schwern I merge the branches in a temporary branch. I find it easier to just go ahead and delete the temporary branch later if things don't work. I understand that this might not be the most effective way but its something I've gotten used to – Irfan Harun Oct 01 '20 at 13:30
  • 1
    @IrfanHarun Fair nuff. I can't tell you why you're not getting a conflict. However, `git merge` takes different "merge strategies" because one size doesn't fit all, try playing with them. You could also play with different merge tools with `git mergetool`. – Schwern Oct 01 '20 at 20:58
  • The following hack that solved this issue : doing git diff made me realized that since there `-` sign before renewal_counter, git was going to remove it irrespective of whichever strategy is tried using. to ensure that git treats my line as a newly added line, i added a new line above and below my line and created a new commit in my feature branch. That way, when i created a temporary branch and merged my development branch, i got a conflict for my `renewal_counter` line. Though this worked, this was a work around and waiting to learn as to why i got the error in the first place – Irfan Harun Oct 02 '20 at 11:35

0 Answers0