Video in progress
Every PR conflicts in `pom.xml`, `application.yml` or a shared `ErrorCode` enum. How do you reduce this at the repo and code structure level?
Conflicts often come from "hot" files that everyone is forced to write to. I split them up: versions go to a BOM, configuration to separate files per module, and central lists move closer to the module. For the rest, ordering rules help.
📖 Answer
First I measure which files change most:
git log --since="3 months ago" --name-only --format= | sort | uniq -c | sort -rn | head -15
Usually 3-4 files sit at the top of the list, and they are in everyone's PR.
The methods:
- Appending at the end. If two PRs each add one element to the end of a list, Git gives a conflict. A rule of keeping the list in alphabetical order spreads the additions over different places;
- The central enum. Instead of a 300-line
ErrorCode, each module has its own codes (PaymentError,OrderError) behind a shared interface. A bonus: coupling between modules goes down too; application.yml. A module keeps its own settings in its own@ConfigurationPropertiesclass and a separate file, attached to the shared file withspring.config.import;pom.xml. Versions live independencyManagementor a BOM module, and the servicepom.xmlfiles have dependencies without versions;- A hand-maintained CHANGELOG. Each PR adds a separate fragment file (
changelog.d/1234.md), collected into one file at release time, or generated from commits; - Flyway. Timestamp-based versions mean there is no "queue" for a number.
There is also merge=union in .gitattributes: it keeps the lines of both sides. But it is right only for files whose lines are independent of each other. If you use it on Java or YAML, you get a broken file.
If even after all of this the same place always conflicts, it is often an architecture signal: a single class has taken on too many responsibilities.
Sign up to mark studied questions and save your progress.