在 gitbash 中使用 git pull 运行批处理文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26016306/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:25:43  来源:igfitidea点击:

Run batch file with git pull in gitbash

gitbatch-filegit-bash

提问by Sowiarz

I have a following problem. I want to write batch file and run this file everyday on vm.

我有以下问题。我想编写批处理文件并每天在 vm 上运行此文件。

I have a ssh key on vm so if I manually write "git pull" in gitbash I do not have to write password after that.

我在 vm 上有一个 ssh 密钥,所以如果我在 gitbash 中手动编写“git pull”,之后我不必再输入密码。

Now I want to write script in batch file which will do that automatically.

现在我想在批处理文件中编写脚本,它会自动完成。

c://TESTS/test/tes- I want to pull only this one folder from repo.

c://TESTS/test/tes- 我只想从 repo 中提取这个文件夹。

I do not know how to create that kind of script. Any ideas?

我不知道如何创建那种脚本。有任何想法吗?

回答by Sowiarz

I found solution in basic cmd:

我在基本 cmd 中找到了解决方案:

cd c://TESTS/path
set HOME=%USERPROFILE%
git pull 
pause

I missed a HOME variable. Now it is working without using git.exe or bash.exe.

我错过了一个 HOME 变量。现在它可以在不使用 git.exe 或 bash.exe 的情况下工作。

回答by Bartlomiej Lewandowski

Since git is not in your PATH you need to add it in your batch script.

由于 git 不在您的 PATH 中,您需要将它添加到您的批处理脚本中。

@echo off
set PATH=%PATH%;C:\path\to\git
cd c://TESTS/test/tes
git pull

回答by Nikhil Dinesh

If git is not added to your environment variable, follow below code block

如果 git 未添加到您的环境变量中,请遵循以下代码块

@echo off
set PATH=%PATH%;C:\Program Files\Git\cmd
git pull

If it is already added.

如果已经添加了。

git pull

this is enough in your bat file. This file should be in your folder where you have checkout the files

这在你的 bat 文件中就足够了。这个文件应该在你签出文件的文件夹中