Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Git merge driver with no rename detection

Tags:

git

merge

I would like to set up a Git repository with a custom merge driver, and then disable rename detection when merging.

The problem is that, if I use the default recursive strategy, I cannot disable rename detection, and if I use the resolve strategy (not ideal, but good enough), the merge driver is ignored.

Note that I would like to avoid rename detection even when the file contents perfectly match.

.git/config:

[merge "my"]
    name = my merge
    driver = my_merge_driver %A %O %B
[merge]
    default = my

Attempts:

$ git merge -X rename-threshold=200%  # Equivalent to 100%
$ git merge -s resolve                # Custom driver ignored
$ git --version                       # git version 2.2.0-rc0
like image 502
filipos Avatar asked Feb 01 '16 16:02

filipos


People also ask

What is the best merge strategy in git?

Resolve is generally considered a safe and fast merge strategy. However, it can only resolve two heads—your current branch and the one you're pulling from—with a three-way merge algorithm. Resolve is suitable for criss-cross merge situations as well as “regular” merges where the merge history might be complex.

Why you should rebase instead of merge?

But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch. The major benefit of rebasing is that you get a much cleaner project history. First, it eliminates the unnecessary merge commits required by git merge .

What is git merge -- no FF?

In the event that you require a merge commit during a fast forward merge for record keeping purposes you can execute git merge with the --no-ff option. git merge --no-ff <branch> This command merges the specified branch into the current branch, but always generates a merge commit (even if it was a fast-forward merge).

What is ORT strategy in git?

ort. This is the default merge strategy when pulling or merging one branch. This strategy can only resolve two heads using a 3-way merge algorithm.


2 Answers

As of Git 2.8.0.rc0, the merge-recursive algorithm now accepts an option "no-renames" (commit 4ce064d), so my problem is now solved by

$ git merge -X no-renames
like image 182
filipos Avatar answered Sep 22 '22 23:09

filipos


Taking into account the use case you're planning for this, A good workaround would be to write the filename, along with the version number, in each file.

like image 22
thePiGrepper Avatar answered Sep 22 '22 23:09

thePiGrepper