git 你如何解决yarn.lock中的git冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42939113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:41:26  来源:igfitidea点击:

How do you resolve git conflicts in yarn.lock

javascriptgitnpmyarnpkg

提问by Christian Schlensker

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?

当多个 git 分支修改使用Yarn的项目中的依赖项时,很可能会在 yarn.lock 文件中引入冲突。删除并重新生成yarn.lock 文件不是一个好主意,因为这可能会导致多个包被无意升级。快速解决此文件中的冲突的最佳方法是什么?

回答by Vanuan

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

从 Yarn 1.0 开始,这很容易,因为它内置了对这种情况的支持。只需运行这个:

$ yarn install

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

Now you only have to do git add yarn.lock && git rebase --continue

现在你只需要做 git add yarn.lock && git rebase --continue

回答by Christian Schlensker

A good approach is detailed in this github discussionabout the issue.

这个 github 讨论中详细介绍了一个很好的方法。

git rebase origin/master

When the first conflict arises, I checkout the yarn.lockthen re-perform the installation

git checkout origin/master -- yarn.lock 
yarn install

This generates a new yarn.lockbased 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
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

回答by pymen

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

我使用可执行的交互式 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"