git在Windows上提交并通过批处理文件推送

 大学城贝岗彩虹屋屋公寓 发布于 2023-02-12 17:44

我经常做同样的任务,即将更改提交到远程分支.有时懒惰,我需要放置一组git命令来自动执行这些步骤:

cd D:\wamp\www\projectName
git checkout dev
git add .
git commit -am "made changes"
git push
pause

我也尝试过:

cd D:\wamp\www\projectName
call git checkout dev
call git add .
call git commit -am "made changes"
call git push
pause

cd D:\wamp\www\projectName
git.exe checkout dev
git.exe add .
git.exe commit -am "made changes"
git.exe push
pause

最终push命令的一切都是令人兴奋的.这是输出:

D:\wamp\www\givingcircle>git checkout dev
Already on 'dev'
Your branch is ahead of 'origin/dev' by 1 commit.

D:\wamp\www\givingcircle>git add .

D:\wamp\www\givingcircle>git commit -am "made changes"
# On branch dev
# Your branch is ahead of 'origin/dev' by 1 commit.
#
nothing to commit, working directory clean

D:\wamp\www\givingcircle>git push
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

D:\wamp\www\givingcircle>pause
Press any key to continue . . .

如你所见,因为push,我得到:

D:\wamp\www\givingcircle>git push
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

当我通过git shell本身运行上面的命令时,一切正常.我还在Windows Path env变量中添加了git.

有没有人知道为什么它适用于git shell而不是批处理命令?(即使其他命令工作但没有push)

1 个回答
  • 对我来说,默认情况下,Windows .sh使用Git Bash正确执行文件.所以我会把你的脚本编写为常规的bash shell脚本:

    #!/bin/sh
    cd /d/wamp/www/projectName
    git checkout dev
    git add .
    git commit -am "made changes"
    git push
    echo Press Enter...
    read
    

    2023-02-12 17:47 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有