当多个git分支修改使用Yarn的项目中的依赖项时,很可能会在yarn.lock文件中引入冲突。删除和重新生成yarn.lock文件不是一个好主意,因为这可能会导致无意中升级多个包。快速解决此文件中冲突的最佳方法是什么?
答案 0 :(得分:92)
Since Yarn 1.0这很简单,因为它内置了对此方案的支持。跑吧:
$ yarn install
yarn install v1.0.1
info Merge conflict detected in yarn.lock and successfully merged.
[1/4] Resolving packages...
现在你只需做git add yarn.lock && git rebase --continue
答案 1 :(得分:41)
this github discussion详细介绍了有关此问题的好方法。
git rebase origin/master
当第一次冲突发生时,我结账
yarn.lock
然后重新执行安装git checkout origin/master -- yarn.lock yarn install
这会产生一个 新的
yarn.lock
基于yarn.lock的origin / master版本,但是 包括我对package.json
所做的更改。那么这只是一个问题:git add yarn.lock git rebase --continue
答案 2 :(得分:0)
我使用的是可执行交互式bash脚本,而不是 rebase ,该脚本只能获取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"
答案 3 :(得分:0)
这个文件太长,所以如果你需要在没有终端的情况下检查 vscode 中的冲突,你可以尝试在这个文件中搜索诸如:>>>>>>>
、=======
、<<<<<<<
或HEAD