NOTE: This guide is ONLY for devs who don't want to edit their
yarn.lock
file by hand. If you don't care about that please carry on.
So you've pulled the latest master
git checkout master
git pull
And checked out your favorite branch but when you try to merge master into it...
git checkout my-awesome-feature
git merge master
Uh-oh! Both your fave branch and master have changed stuff in yarn.lock
CONFLICT (content): Merge conflict in package.json
CONFLICT (content): Merge conflict in yarn.lock
Sure you could probably fix the package.json conflict "by hand" but the lockfile should not be touched 💩
All sorts of naughty thoughts might be going through your head at this point including conflict fix branches,
merge stategies or even god-forbid... a rebase
⏰⬅️🚗💨
But fear not my troubled friend, there's no need to go that far, here's how you can fix this in 3 easy steps:
- Write down the exact package names and versions that your branch added/removed/upgraded (eg:
left-pad@^1.1.3
). - Checkout and stage
package.json
andyarn.lock
frommaster
.
git checkout --theirs package.json
git checkout --theirs yarn.lock
git add package.json yarn.lock
- Re-apply the packages you wrote down in step 1 (eg:
yarn add left-pad@^1.1.3
).
Now the conflicts should be all gone and you're free to go on your way (commit the merge or fix other unrelated conflicts).
Just run
yarn install
. Yarn has a built-in mechanism to fix conflicts if it detects them present in the lock file.