Visual Studio代码自动推送

kag*_*kij 25 git push visual-studio-code

是否有可能在自动提交后进行git push?现在我需要在手动提交后点击push,这不是很舒服.

Jos*_*ger 31

更新2018-12-20

最新版本的VS Code具有在提交时推送或同步的设置.

  • 转到VS代码设置菜单(左下角的齿轮>设置)
  • 搜索 git.postCommitCommand
  • 选择你的选择

旧的解决方法

我也想念这个.这是目前的"解决方法" -

code .git/hooks/post-commit

复制并粘贴以下内容 -

#!/usr/bin/env bash

branch_name=`git symbolic-ref --short HEAD` 
retcode=$?
non_push_suffix="_local"

# Only push if branch_name was found (my be empty if in detached head state)
if [ $retcode = 0 ] ; then
    #Only push if branch_name does not end with the non-push suffix
    if [[ $branch_name != *$non_push_suffix ]] ; then
        echo
        echo "**** Pushing current branch $branch_name to origin [i4h_mobiles post-commit hook]"
        echo
        git push origin $branch_name;
    fi
fi
Run Code Online (Sandbox Code Playgroud)

确保它是可执行的 -

chmod +x .git/hooks/post-commit

再试一次.

Creds:


voi*_*der 7

我使用 Gitlens 扩展来更轻松地推送提交。

  1. 安装 Gitlens 扩展。
  2. 转到设置 -> 扩展 -> Git -> 提交提交命令,从下拉列表中选择“推送”。
  3. 在您的代码中进行一些更改。
  4. 前往 gitlens 选项卡,添加提交注释,暂存更改并点击“提交”(勾号)。后提交命令将负责其余的工作。

这就对了。它很简单,使用起来非常快,而且您根本不需要 CLI。


wgj*_*wgj 0

VSCode 的 Git 前端似乎没有内置类似的东西,但有一个选项可以删除安全检查。 "git.confirmSync": false使用 VSCode 内置的推送/远程同步时将删除确认对话框。

@Mistermatt 的链接看起来像你所要求的,但我在盲目地推动自己方面遇到了太多问题:)。