Resolve .env Merge Conflicts Safely
Admin ·
A conflict in a deployment’s .env file can put a testing port beside a production banner. Decide whether you have Git’s conflict file or two complete versions. That choice determines whether you resolve a block at a time or review changes by variable name.
Read both versions of the conflict block
Choose File with Git conflict markers and select Load example, then Find conflicts. The conflict starts on line 3. The first side contains PORT=08080 and a Testing #1 banner. The second side contains PORT=00443 and a Production #1 banner. Open Show common ancestor to see the old PORT=3000 in the diff3 block.
Keep second version and build the resolved file. Check that the download has STORE_ID=0012, PORT=00443, the quoted Production #1 banner, and EMPTY=. The inventory comment stays above the assignments. Change the choice to Keep first version and rebuild to see PORT=08080 and the Testing #1 banner.
Git merge manual, how conflicts are presentedNode.js dotenv syntax
Compare complete files by variable name
Switch to Compare two versions and load its example. A conflict appears for PORT. Both files set ENABLED to the string false even though one version uses quotes. Choose a port and build. The output keeps EMPTY= from the first file and REGION=eu from the second.
Review one-sided variables against the intended deployment. A two-version comparison cannot distinguish an addition from a deletion. This mode exports assignments, dropping standalone comments. Use Git marker mode when you want to keep the text surrounding conflicts.
Check the result before replacing the working file
If building the resolved file reports a duplicate, use its two line numbers to find the repeated setting and revisit the side you chose. If both choices leave an issue, edit the supplied text, find the conflicts again and rebuild.
Reopen the download in the .env Validator. Check the syntax, then compare the values with your deployment’s expected configuration before staging the resolved file. Git’s merge manual describes how to mark a file resolved once the working copy is ready.
Git merge manual, how conflicts are presentedNode.js dotenv syntax
Common questions
Does Keep second version keep the common ancestor?
It uses the lines after the equals-sign divider. In diff3 and zdiff3, the ancestor appears between the vertical-bar marker and the divider for comparison.
How do I keep a key from each side of the same Git block?
Edit the input with the combination you intend or compare clean copies of the two versions. The conflict-block selector takes a whole side, including an empty side when it represents deleted lines.