I would like to avoid git auto merging my composer.json. This way I can have a composer.json in develop branch that uses dev-develop packages, while the one in master only uses dev-master packages.
I could use two composer.json files as suggested here, but I am afraid that I will end up forgetting to add a bundle in my composer.json for master. Especially when automating tasks, this can end up in a disaster.
So actually I would like git to either:
While I do tend to agree that the particular scenario you describe might indicate that you have deeper issues with your development process, git can be made to do what you ask pretty easily by setting the merge
attribute on the file in question, to one of two values. From the "Performing a three-way merge" section of git help attributes
, they are:
merge
unsetTake the version from the current branch as the tentative merge result, and declare that the merge has conflicts. This is suitable for binary files that do not have a well-defined merge semantics.
To establish this, do:
echo "composer.json -merge" >> .gitattributes
merge=binary
Keep the version from your branch in the work tree, but leave the path in the conflicted state for the user to sort out.
To establish this, do:
echo "composer.json merge=binary" >> .gitattributes
These descriptions don't really make clear how the behaviour would differ, and indeed, upon testing, both of them produce this output:
$ git merge develop
warning: Cannot merge binary files: composer.json (HEAD vs. develop)
Auto-merging composer.json
CONFLICT (content): Merge conflict in composer.json
Automatic merge failed; fix conflicts and then commit the result.
$ git status
On branch attr-test-2
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: composer.json
no changes added to commit (use "git add" and/or "git commit -a")
Since the semantics you want are not necessarily to declare that this file is binary, but just to tell git not to merge it automatically, -merge
seems ever so slightly preferable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With