2

I've created my own dev branch from a pretty active repository. This repository (Clappr) also contains a compiled and minified file, which is updated with the source code.

Whenever I want to rebase my dev branch with the master, this file is conflicting, because it cannot be automatically merged—of course, because it's a minified JS file:

$ git checkout dev
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: dummy commit
Using index info to reconstruct a base tree...
M   dist/clappr.js
M   src/playbacks/hls/hls.js
Falling back to patching base and 3-way merge...
Auto-merging src/playbacks/hls/hls.js
Auto-merging dist/clappr.js
CONFLICT (content): Merge conflict in dist/clappr.js

I can resolve this conflict using --ours, but I have to do this for every single commit on master that I haven't rebased yet.

I know I can skip a patch entirely, but can I somehow automatically tell Git to ignore that clappr.js file and just always use whatever is in my dev branch?

slhck
  • 36,575
  • 28
  • 148
  • 201

1 Answers1

3

You can define a custom merge driver (as in "Git: How to rebase many branches (with the same base commit) at once?" for a concrete example).

That merge driver "keepMine" associated with dist/clappr.js, and declare that merge driver in a .gitattributes file present in each of your branches.
See "How do I tell git to always select my local version for conflicted merges on a specific file?".

echo clappr.js merge=keepMine > dist/.gitattributes
git config merge.keepMine.name "always keep mine during merge"
git config merge.keepMine.driver "keepMine.sh %O %A %B"

With keepMine.sh put somewhere in your $PATH, not in the repository:

# I want to keep MY version when there is a conflict
# Nothing to do: %A (the second parameter) already contains my version
# Just indicate the merge has been successfully "resolved" with the exit status
exit 0

(For a KeepTheir.sh, see "How to stop a merge (yet again…)")


Even simpler, as noted by branch14 in the comments:

Linux already has a command that successfully does nothing, aptly named "true".

git config merge.keepMine.driver "true"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Linux already has a command that successfully does nothing, aptly named "true". No need for `keepMine.sh`, just use `git config merge.keepMine.driver "true"`. – branch14 Aug 25 '20 at 09:43
  • @branch14 Thank you. That must have slipped my mind when I wrote this 5 years ago. I have edited the answer to include your comment, for more visibility. – VonC Aug 25 '20 at 11:47