Klaus Native
Klaus Native

Reputation: 3509

How to force manual merging in Git / IntelliJ if same file but different lines were edited?

I am not sure whether this is a Git or IntelliJ problem we are facing. Assuming the following using Git integration in IntelliJ:

  1. User A changes a text file and commits and pushes this change to branch branch1

  2. User B changes the same text file but in a different line and commits to branch1

  3. User B fetches the remote repository and merges the remote branch1 into the local branch1

Current Behavior: It merges wihout any conflicts (since different lines?)

Wanted Behavior: Conflict Resolution Window popups up and User must decide whether to apply all none conflicting changes.

But why you might want this behvaior?: Sometimes we had troubles with markup or js files, where one developer changed something at the top (e.g. removed an unused function) and a another developer was relying on this. One must have very costly ui tests if you want to get informed about those breaks. Especially if it is just markup (e.g. jsf tags, params)

Upvotes: 2

Views: 3860

Answers (2)

joanpau
joanpau

Reputation: 568

I am not sure if this is what you want, but you could use the --no-commit option of the git merge command to pretend the merge failed even when there are no conflicts. From the manual:

With --no-commit perform the merge but pretend the merge failed
and do not autocommit, to give the user a chance to inspect and
further tweak the merge result before committing.

Then, you can inspect the changes with git diff with --cached option to inspect the results of the merge; and use git checkout with options --ours and --theirs to accept or refuse the changes introduced by the merge.

Upvotes: 3

ThanksForAllTheFish
ThanksForAllTheFish

Reputation: 7251

That seems a strange behavior you want. With your last edit I get why you want, but I think you want to use a tool to solve problems which do not concern the tool itself.

I do not have a direct answer, and I do not even think there is an option to force merge review. However, you may develop a merge process in which you asked your coworker to make a diff before the merge. So basically:

  1. do the changes on your local machine
  2. git diff REMOTE/BRANCH -- files
  3. ask the developer to review the changes
  4. if everything went as hoped, commit and push the changes. Otherwise, undo the unwanted changes, and repeat from 2.

As you can see, the process becomes really clumsy and slow and it remains error-prone (if I delete a line, I typically know what I am deleting and if no test gets broken I may be asked to review the deletion hundreds of times and still keep it).

So far, this is the only help I am able to suggest you, if you find any way to achieve your goal in a more direct way, please comment this answer, or provide your own solution, I am always glad to learn something new!

Upvotes: 1

Related Questions