【问题标题】:How do you resolve git conflicts in yarn.lock如何解决 yarn.lock 中的 git 冲突
【发布时间】:2017-08-13 19:51:24
【问题描述】:

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

【问题讨论】:

    标签: javascript git npm yarnpkg


    【解决方案1】:

    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 的回答所说的去做。
    • @theGreenCabbage 不信,试试看
    • 你需要先解决 package.json 中的冲突,然后运行 ​​yarn,它应该会处理它
    • 它为我打印出“成功合并”的消息,但 yarn.lock 仍然包含合并冲突。
    • 这可行,但 webstorm 仍然显示冲突,如何将其标记为已解决?
    【解决方案2】:

    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
    

    【讨论】:

    • 对于这个和公认的答案,我必须多次重复命令,git 会得到以下结果: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.
    • 我的修复以常规合并中的这些步骤结束 - 它从未在我的 rebase 上工作过。
    【解决方案3】:

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

    【讨论】:

      【解决方案4】:

      这个文件太长了,所以如果你需要在没有终端的情况下检查 vscode 中的冲突,也许你可以尝试在这个文件中搜索以下术语:>>>>>>>=======<<<<<<<HEAD

      【讨论】:

        猜你喜欢
        • 2018-05-15
        • 1970-01-01
        • 2010-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-11
        • 2011-10-05
        • 2023-03-21
        相关资源
        最近更新 更多