如何使用 Visual Studio Code git push 到不同的分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38349811/
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:06:06  来源:igfitidea点击:

How to git push to a different branch with Visual Studio Code?

gitvisual-studio-code

提问by CPHPython

I realized that after a commit in VSCode there's a "Push" menu option that pushes the commit to the default branch.

我意识到在 VSCode 中提交之后,有一个“推送”菜单选项可以将提交推送到默认分支。

However, I often need to push it as well to different branches. Is there a way to do this or run git push --progress "origin" DEFAULT_BRANCH:OTHER_BRANCHthrough VSCode?

但是,我经常需要将它推送到不同的分支。有没有办法做到这一点或git push --progress "origin" DEFAULT_BRANCH:OTHER_BRANCH通过 VSCode运行?

回答by CPHPython

Edit 2019-08-16

编辑 2019-08-16

VS Code now has a specific option to allow a Push to...a specific remote(not a branch) through the ...(hover the repo in the source control tab Ctrl+Shift+G) OR through F1+type push to.

VS Code 现在有一个特定选项,允许通过(将 repo 悬停在源代码控制选项卡+ + 中)或通过+type push to允许推送到...特定远程(不是分支)。...CtrlShiftGF1

TLDR;(re-answering the question)

TLDR;(重新回答问题)

  1. switch to the branch to push – F1+ type Checkout to...(instead of the old Git Branchoption) or choose a Create Branchoption
  2. Stage your changes – F1+ type stage(choose one of the Git:options)
  3. Commit your changes – F1+commit
  4. F1+Git: Pushpushes the branch you previously created or checked out (using the same name).
  1. 切换到要推送的分支 – F1+ 键入Checkout to...(而不是旧的Git Branch选项)或选择Create Branch选项
  2. 暂存您的更改 – F1+ 输入stage(选择Git:选项之一)
  3. 提交您的更改 – F1+提交
  4. F1+ Git:推送您之前创建或签出的分支(使用相同的名称)。

Original answer

原答案

After all it's possible, this is a non direct way of pushing into another branch with VSCode, so answering my own question:

毕竟这是可能的,这是使用 VSCode 推送到另一个分支的非直接方式,所以回答我自己的问题:

  1. Switch to the other branch – F1+Git Branch+ENTER, type the name of the branch and press ENTERagain (once the exact name of the branch is typed, it will show its id in the autocomplete dropdown or inform you that that's the current branch);
  2. Stage your changes by selecting the files for commit;
  3. Commit the staged files (or all) and click ...and Push.
  1. 切换到另一个分支 – F1+ Git Branch+ ENTER,输入分支名称并ENTER再次按下(一旦输入分支的确切名称,它会在自动完成下拉菜单中显示其 id 或通知您这是当前分支);
  2. 通过选择要提交的文件来暂存您的更改;
  3. 提交暂存文件(或全部)并单击...推送

You can later switch back to your initial branch with F1+Git Branch+ENTER+[branch name]+ENTER. The only problem with this is that VSCode does not allow you to push again those same changes back to the initial branch (even with F1+Git Push).

您可以稍后使用F1+ Git Branch+ ENTER+[ branch name]+切换回初始分支ENTER。唯一的问题是 VSCode 不允许您将相同的更改再次推送回初始分支(即使使用 F1+Git Push)。