Forcing 'git merge' to declare all differences as merge conflict

In 'git merge', I would like any difference, even if usually not a merge conflict, to be considered a merge conflict. Then, using 'git mergetool, I see and resolve all the differences. I tried specifying '* -merge' in .gitattributes, but this did not seem to work:

$ git checkout master Switched to branch 'master' $ ls foo.c $ git merge add-on Updating a628824..2219552 Fast-forward 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 bar.c $ cat .gitattributes * -merge $ ls bar.c foo.c 

For the above 'git add-on merge' I was expecting a merge conflict for bar.c without the base version, without the local version and with the remote version. [edit] As suggested in one answer, the merger did not happen above. Here is the case when I forced the merge, there was still no desired merge conflict:

 $ git merge --no-ff add-on Merge made by the 'recursive' strategy. 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 bing.c 

Note that in the above, “bing.c” is actually empty; but this is not a problem because the provision of a non-empty file is still merged. [edit 2] I tried --no-commit with this result:

 $ git merge --no-ff --no-commit add-on Automatic merge went well; stopped before committing as requested $ git status # On branch master # Changes to be committed: # # new file: boom.c # $ git mergetool No files need merging $ cat .gitattributes * -merge 

What am I missing? Is there a way to confirm that ".gitattributes" is getting used / read?

+6
source share
3 answers

You have not merged. Your git merge add-on command has been fast-forward, which means that it just moved the branch branch. This is because your add-on branch has already converged from the tip of the master branch, so no merging was required. If you run git log , you will see that there will be no commit.

In principle, before the merger, it looked like this:

  master / o---o---o---o add-on \ / o---o---o 

and merging just moved the master pointer to the end of the line:

  master, add-on / o---o---o---o---o---o---o 

If you want to force a merge, skip the --no-ff flag, as in git merge --no-ff add-on .


Upon further reflection, the merge attribute will not do what you want. This applies only to file-level merging, which means that both sides of the merge have changes to a specific file. If only one side has changes (this is your case), the file level merge is not performed, and the changed file is accepted unconditionally.

It is best to use git merge --no-ff --no-commit add-on to create a merge, but not actually commit. Now you can check the results and tune them to your satisfaction before you merge. If you want to accept the changes based on each column, you can do something like git reset to reset the index, and then git add -p to execute each console.

+6
source

You may try:

 git merge --no-commit 

What will make GIT not pass merge changes. Alternatively, if you want this to be fixed when there is no conflict but not to lose the source branch, this is no-ff:

 git merge --no-ff 

Both can be used if necessary.

Read more here: Why is GIT Accelerated Merge by Default?

+2
source

I have a similar desire and failed to do this with automatic tools. Here is a semi-automatic solution:

From master , merge add-on and manually allow changes:

Start with:

 git merge --no-ff --no-commit add-on 

Then for each changed file do:

 git show master:path/to/file > from_master git show add-on/to/file > from_add-on kdiff3 --qall from_master from_add-on -o path/to/file git add path/to/file 

Finally,

 git commit 

Why is this a 90% solution?

This solution merges even into “obvious situations”, and it does not force me to install .gitattributes, so I can make the “manual merge” behavior depend on who I am merging with and why, and not on what files I'm going to.

0
source

Source: https://habr.com/ru/post/913074/


All Articles