Git never (auto) merge composer.json

I would like to avoid git automatically merging my composer.json. That way, I can create composer.json in a development branch that uses dev-develop packages, while one in master uses only dev-master packages.

I could use two composer.json files, as suggested here , but I'm afraid that in the end I will forget to add the package to my composer.json for the wizard, Especially when automating tasks, this can end in disaster.

So I really would like to git either:

  • Always conflict when composer.json is merged, so I can manually edit it before proceeding with the branch.
  • Merge only by the number of lines. So, if a package is added / removed, the number of lines changes, then it should merge, conflicts, whatever. If the contents of a string change, it can ignore this.
+4
source share
1 answer

Although I am inclined to agree that the scenario you described may indicate that you have more serious problems with the development process, git can be made so that you can easily cope by setting the attribute mergein the file in the question to one of two values. From the “Performing a Three-Way Merger” section, git help attributesthey:

merge unset

, . , .

, :

echo "composer.json -merge" >> .gitattributes

merge=binary

, .

, :

echo "composer.json merge=binary" >> .gitattributes

, , , , :

$ 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")

, , , , git , -merge .

+1

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


All Articles