【发布时间】:2017-08-13 19:51:24
【问题描述】:
当多个git分支在一个使用Yarn的项目中修改依赖时,很可能会在yarn.lock文件中引入冲突。删除并重新生成 yarn.lock 文件不是一个好主意,因为这可能会导致多个包被无意升级。快速解决此文件中的冲突的最佳方法是什么?
【问题讨论】:
标签: javascript git npm yarnpkg
当多个git分支在一个使用Yarn的项目中修改依赖时,很可能会在yarn.lock文件中引入冲突。删除并重新生成 yarn.lock 文件不是一个好主意,因为这可能会导致多个包被无意升级。快速解决此文件中的冲突的最佳方法是什么?
【问题讨论】:
标签: javascript git npm yarnpkg
Since Yarn 1.0 这很简单,因为它内置了对这种场景的支持。
首先手动解决package.json中的冲突,然后运行这个:
$ yarn install
yarn install v1.0.1
info Merge conflict detected in yarn.lock and successfully merged.
[1/4] Resolving packages...
然后冲突将得到解决,您可以提交该问题,或者如果您正在这样做,则继续重新设置基准。
【讨论】:
yarn.lock 中包含 ============、>>>>>>>>>>>>>>、<<<<<<<<<<<<< 等代码行存在冲突,我认为这不起作用。您仍然需要按照 Christine Schlensker 的回答所说的去做。
this github discussion 中详细介绍了有关该问题的好方法。
git rebase origin/master当第一个冲突出现时,我结帐
yarn.lock然后重新执行安装git checkout origin/master -- yarn.lock yarn install这会生成一个 新的
yarn.lock基于 yarn.lock 的原始/主版本,但是 包括我对package.json所做的更改。那么这只是一个问题:git add yarn.lock git rebase --continue
【讨论】:
No changes - did you forget to use 'git add'? If there is nothing left to stage, chances are that something else already introduced the same changes; you might want to skip this patch.
我使用 可执行交互式 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"
【讨论】:
这个文件太长了,所以如果你需要在没有终端的情况下检查 vscode 中的冲突,也许你可以尝试在这个文件中搜索以下术语:>>>>>>>、=======、<<<<<<< 或 HEAD
【讨论】: