Git:如何使用 VS Code 源代码管理将功能分支 merge 到 master 中?

标签 git visual-studio-code merge branch git-merge

我使用 Visual Studio 源代码管理在 Git 中创建了一个功能分支。
现在我想使用 Visual Studio Code 将功能分支 merge 到 master 中。
执行此操作的正确过程是什么?

最佳答案

开始 VS 代码 1.48 ,许多 Git 命令现在可以作为源代码控制面板的菜单选项使用,包括 merge 分支。见 "New Git View submenus" section of the July 2020 (1.48) release notes :

Thanks to the new submenu proposed API, the Git View and More Actions (...) menu has been refactored for better organization of several commands:


enter image description here
merge 分支(例如 merge featureA 到 master):
  • 选择目标分支(例如 master )
  • 选择 ... > Checkout to... enter image description here
  • 选择分支
    enter image description here

  • 选择要 merge 的分支(例如 featureA )
  • 选择 ... > Branch > Merge Branch... enter image description here
  • 选择分支
    enter image description here

  • 推送更新的分支(例如 master )
  • 选择 ... > Pull,Push > Push enter image description here


  • VS Code 1.48 之前 , VS Code Source Control 没有用于 merge 分支的 UI。但是您可以使用来自 Command Palette 的命令进行 merge 。 .
    merge 分支(例如 merge my-feature-branch master ):
  • checkout 目标分支( master )
  • 命令面板 > Git:结帐到...
  • 选择分支
    enter image description here

  • 确保大师与 Remote 同步
    enter image description here
  • merge 功能分支
  • 命令面板 > Git: merge 分支..
  • 选择分支
    enter image description here

  • 确认 merge
  • 如果 merge 在没有冲突的情况下完成,您现在应该从源代码管理 UI 或状态栏看到您现在有需要推送到远程的新提交。 ( merge 操作仅在您本地的 repo 副本中执行)。
    enter image description here


  • 虽然使用 VS Code 源代码控制 UI 可以工作,但我强烈建议学习如何从命令行使用 Git,因为它们使用起来更简单,但它们可以让您更好地控制 Git 操作。另外,它们甚至可以在 VS Code 之外工作,只要您可以访问终端。
    例如,可以从终端执行相同的分支 merge 操作。
    $ git checkout master
    $ git pull
    $ git merge my-feature-branch
    $ git log
    commit 54971a1cc845459742392061e71ef4fcb2444357 (HEAD -> master)
    Merge: e8fad11 b1d9050
    Author: XXX
    Date:   Wed May 13 20:14:15 2020 +0900
    
        Merge branch 'my-feature-branch'
    ...
    
    了解 Git 的最佳地点在这里:https://git-scm.com/book/en/v2 .
    专用于 git merge :
  • 3.2 Git Branching - Basic Branching and Merging
  • What is the best (and safest) way to merge a Git branch into master?
  • 关于Git:如何使用 VS Code 源代码管理将功能分支 merge 到 master 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61755744/

    相关文章:

    git - 使用 gitflow 为 git 用户提供了什么?

    javascript - Visual Studio Code 正在破坏自关闭标签

    flutter - 有没有办法在 vscode/visual studio code flutter 中自动填充所需的类/小部件属性?

    react-native - Visual Studio 代码错误 :-Failed to start flow Error: Wrong version of Flow. 配置指定版本 ^0.92.0 但这是版本 0.95.1

    git - 如何在不使用 reset 的情况下撤消 git 中的快进 merge

    git - Git 中分支之间未跟踪的文件

    git - 使用不需要的未跟踪文件重新定位。错误 merge

    git - Mingw-w64:ssh-add 工作直到 git fetch(连接到代理时出错:文件描述符错误)

    python - 数据框用其他行替换行

    Git 不允许我 merge