在 VSCode 中将代码推送到 git 的快捷方式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46382883/
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
Shortcut to push code to git in VSCode?
提问by ifconfig
In VS Code, the only way that I know of to push commits with git is to go into the "..." menu of the Source Control tab and click Push
.
在 VS Code 中,我所知道的使用 git 推送提交的唯一方法是进入 Source Control 选项卡的“...”菜单并单击Push
。
That method seems a bit roundabout to me, especially considering that there is a unique button to commit code right in the tab. Is there a way to have a push button be next to the commit button in VS Code Source Control?
这种方法对我来说似乎有点迂回,特别是考虑到选项卡中有一个独特的按钮可以提交代码。有没有办法在 VS Code 源代码管理中的提交按钮旁边有一个按钮?
回答by Irvin Lim
There is a button at the bottom left of the VS Code editor, which you can click to automatically sync your branch with that from remote (i.e. both pull AND push, merging your branch with upstream if necessary). This might or might not be what you want, but it's easy to click this when you know that there are no changes upstream (e.g. when you're working on a project by yourself).
VS Code 编辑器的左下角有一个按钮,您可以单击该按钮以自动将您的分支与远程的分支同步(即拉和推,必要时将您的分支与上游合并)。这可能是您想要的,也可能不是您想要的,但是当您知道上游没有更改时(例如,当您自己处理一个项目时)很容易点击它。
Otherwise, I frequently bring up the Command Palette with ??P (Ctrl-Shift-P on Windows/Linux) and type gpus
, which brings up Git: Push
as the first option. (It's been ingrained in my fingers since the days of Sublime Text)
否则,我经常使用 ??P(Windows/Linux 上的 Ctrl-Shift-P)调出命令面板,然后键入gpus
,这Git: Push
是第一个选项。(自从 Sublime Text 出现以来,它就在我的手指中根深蒂固)
If you are using the later versions of VS Code which has MRU list of command history, you can shorten it even further and just type gp
, which is exactly what I've been using since SublimeGit
in Sublime Text.
如果您正在使用具有命令历史记录 MRU 列表的 VS Code 的更高版本,您可以进一步缩短它,只需键入gp
,这正是我SublimeGit
在 Sublime Text 中一直使用的。
Lastly, another option you may want is to add a custom keyboard shortcut to push changes. You can do this by editing your Keyboard Shortcuts File, and adding something like the following:
最后,您可能需要的另一个选项是添加自定义键盘快捷键来推送更改。您可以通过编辑键盘快捷键文件并添加如下内容来实现此目的:
{
{
"key": "ctrl+alt+p",
"command": "git.push"
}
}