简体   繁体   English

在VSCode中将代码推送到git的快捷方式?

[英]Shortcut to push code to git in VSCode?

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

附件 A

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 源代码管理中的提交按钮旁边放置一个按钮?

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 (ie both pull AND push, merging your branch with upstream if necessary). VS Code 编辑器的左下角有一个按钮,您可以单击该按钮以自动将您的分支与远程的分支同步(即拉和推,如有必要,将您的分支与上游合并)。 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 (eg when you're working on a project by yourself).这可能是您想要的,也可能不是您想要的,但是当您知道上游没有更改时(例如,当您自己处理一个项目时)很容易点击它。

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.否则,我经常使用 ⇧⌘P(Windows/Linux 上的 Ctrl-Shift-P)调出命令面板并输入gpus ,这会调出Git: Push作为第一个选项。 (It's been ingrained in my fingers since the days of Sublime Text) (自从 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 ,这正是我自 Sublime Text 中的SublimeGit以来一直使用的。

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"
    }
}

There is a new setting Post Commit Command in vscode 1.30.1 to change the default commit behavior vscode 1.30.1 中有一个新的设置Post Commit Command来改变默认的提交行为在此处输入图片说明

VSCode has it there but you have to activate it: 1- Go to shortcuts by Command/Ctrl + K + Command/Ctrl + S VSCode 有它,但你必须激活它: 1- 通过 Command/Ctrl + K + Command/Ctrl + S 转到快捷方式

2- Then search for "Git Push" 2-然后搜索“Git Push”

3- Click on the + that appears when you hover over it 3- 单击鼠标悬停在上面时出现的 +

4- Finally write the keyboard shortcut you want 4- 最后写下你想要的键盘快捷键

  • You can also search for Git Pull, Git commit, and even things not related to Git like kill terminal or expand terminal您还可以搜索 Git Pull、Git commit,甚至与 Git 无关的内容,例如 kill terminal 或 expand terminal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM