How do you resolve git conflicts in yarn.lock

JavascriptGitNpmYarnpkg

Javascript Problem Overview


When multiple git branches modify the dependencies in a project that uses Yarn, it is likely to introduce a conflict in the yarn.lock file. It is not a good idea to delete and regenerate the yarn.lock file because this will probably cause several packages to be unintentionally upgraded. What is the best way to quickly resolve conflicts in this file?

Javascript Solutions


Solution 1 - Javascript

Since Yarn 1.0 it's easy because it has built in support for this scenario.

First solve the conflict in package.json manually, then just run this:

$ yarn install

yarn install v1.0.1
info Merge conflict detected in yarn.lock and successfully merged.
[1/4] Resolving packages...

And then the conflict will be resolved and you can commit that or continue rebasing if that was what you were doing.

Solution 2 - Javascript

A good approach is detailed in this github discussion about the issue.

> git rebase origin/master > > When the first conflict arises, I checkout > the yarn.lock then re-perform the installation > > git checkout origin/master -- yarn.lock > yarn install > > This generates a > new yarn.lock based on the origin/master version of yarn.lock, but > including the changes I made to my package.json. Then it's just a matter of: > > git add yarn.lock > git rebase --continue

Solution 3 - Javascript

Instead of rebase i use executable interactive bash script, which fetches only Pipfile.lock Pipfile

#!/usr/bin/env bash
export GIT_TRACE=1
git checkout origin/master -- Pipfile.lock Pipfile
git commit -m "fetch to branch Pipfile.lock, Pipfile from origin/master" -- Pipfile.lock Pipfile
read  -n 1 -p "Do your changes in Pipfile and press Enter ..."
pipenv lock --clear
git commit -m "re-apply changes to Pipfile.lock, Pipfile" -- Pipfile.lock Pipfile
echo "Done"

Solution 4 - Javascript

this file is too long so if you need to check conflict in vscode without terminal maybe you can try a search in this file for terms like: >>>>>>>, =======, <<<<<<< or HEAD

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChristian SchlenskerView Question on Stackoverflow
Solution 1 - JavascriptVanuanView Answer on Stackoverflow
Solution 2 - JavascriptChristian SchlenskerView Answer on Stackoverflow
Solution 3 - JavascriptpymenView Answer on Stackoverflow
Solution 4 - JavascriptMuhammed MoussaView Answer on Stackoverflow