简体   繁体   English

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

[英]git commit and push via batch file on Windows

I do same task often of committing and pushing changes to remote branch. 我经常做同样的任务,即将更改提交到远程分支。 Being lazy sometimes, I needed to put set of git commands to automatically perform these steps: 有时懒惰,我需要放置一组git命令来自动执行这些步骤:

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

I also tried: 我也尝试过:

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

and

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

Everything works excpet for the final push command. 对于最终的push命令,一切都有效。 Here is output: 这是输出:

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 . . .

As you can see, for push , I am getting: 正如你所看到的,对于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.

When I run above commands via git shell itself, everything works fine. 当我通过git shell本身运行上面的命令时,一切正常。 I have also added git to Windows Path env variables. 我还在Windows Path env变量中添加了git。

Does anyone have an idea of why it works on git shell and not on batch command ? 有没有人知道为什么它适用于git shell而不是批处理命令? (even though other commands work but not push ) (即使其他命令有效但不push

For me, by default, Windows executes .sh files correctly using Git Bash. 对我来说,默认情况下,Windows使用Git Bash正确执行.sh文件。 So I would write your script as a regular bash shell script: 所以我会把你的脚本编写为常规的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

Try this one !! 试试这个!!

cd c://TESTS/path
set HOME=%USERPROFILE%
GIT COMMAND GOES HERE
pause

I had a similar need, to be able to move code from BBCloud to our development test servers, for stage 1 testing. 我有类似的需求,能够将代码从BBCloud移动到我们的开发测试服务器,进行第1阶段测试。

To do this, I created a Windows scheduled task: 为此,我创建了一个Windows计划任务:

Under "Actions", I added "C:\\Program Files\\Git\\bin\\bash.exe" in Program/script field (the quotes were required). 在“操作”下,我在程序/脚本字段中添加了"C:\\Program Files\\Git\\bin\\bash.exe" (引号是必需的)。

In the "Add arguments" field, I entered c:\\path\\to\\bash script\\pull.sh . 在“添加参数”字段中,我输入了c:\\path\\to\\bash script\\pull.sh

I then completed the Task Scheduler wizard (run frequency, time, etc.). 然后,我完成了任务计划程序向导(运行频率,时间等)。

I then created a bash script, using Nano in Git Bash for Windows containing: 然后我创建了一个bash脚本,在Git Bash for Windows中使用Nano包含:

#!/bin/bash
cd /c/path/to/bash script
git pull

I would prefer a push to the repository automatically pushing down to the test server, but Pipes, Webhooks, and DeployHQ don't seem to be a solution for our environment. 我更喜欢推送到存储库自动推送到测试服务器,但Pipes,Webhooks和DeployHQ似乎不是我们环境的解决方案。

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

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