通过批处理文件中创建GIT修改文件的归档 [英] Create archive of modified files in GIT via batch file

查看:643
本文介绍了通过批处理文件中创建GIT修改文件的归档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个混帐命令创建中的特定修改过的文件的归档承诺:

  git的存档-o update.zip HEAD $(git的差异--name只的commitid ^)

其中的commitid是的id提交我期待存档。这工作正常,在命令行,但我想从一个批处理文件运行它。下面是我使用的批处理文件的内容:

  git的存档-o update.zip HEAD $(git的差异--name-只有1%^^)

其中,%1正在通过SourceTree传入的提交ID。我遇到的问题是,从一个批处理文件运行时,此命令将返回以下错误:


  

错误:未知的选项'名称只有


我猜可能有一些字符转义问题去,但我无法找到什么特别打破。

如何将我写的Git命令,以便它会从一个批处理文件工作?

更新

我试图消除唯一--name选项并收到以下错误通过SourceTree试图批处理脚本时:


  

致命的:未找到路径:$(GIT


希望这有助于缩小东西可怎么回事。

进一步更新

原来我的语法是错误的,从一个特定的承诺只抓住修改过的文件,但使用msandiford的答案,我想出了这个批处理文件脚本,完美的作品:

  SETLOCAL enabledelayedexpansion
组输出=
FOR / Fdelims =%%一个在('git的差异树--no提交-ID --name只有--r%1 ^^')做(设定的输出!=输出!%%一个 )
Git的存档-o update.zip HEAD%输出%
ENDLOCAL


解决方案

假设你需要一个Windows批处理文件,而不是一个bash脚本,这里是一个最小的批处理文件,可能会做你想要什么:

  SETLOCAL enabledelayedexpansion
组输出=
FOR / Fdelims =%%一个在('git的差异--name-只有1%^^')做(设定的输出!=输出!%% A)
Git的存档-o update.zip HEAD%输出%
ENDLOCAL

它的工作原理通过收集 git的差异... 命令输出的所有行成一个环境变量,然后使用该执行 git的存档... 操作。

对于Windows文档命令这里包括 /˚F开关。为 SETLOCAL 命令文档这里

I'm using this git command to create an archive of the files modified within a specific commit:

git archive -o update.zip HEAD $(git diff --name-only COMMITID^)

where COMMITID is the id of the commit I'm looking to archive. This works fine from the command line but I would like to run it from a batch file. Here are the contents of the batch file I'm using:

git archive -o update.zip HEAD $(git diff --name-only %1^^)

where %1 is the commit id being passed in via SourceTree. The problem I'm having is that this command when run from a batch file returns the following error:

error: unknown option `name-only'

I'm guessing there may be some character escaping issues going but I'm unable to find what is specifically breaking.

How would I write that git command so that it will work from a batch file?

UPDATE

I tried removing the --name-only option and received the following error when trying the batch script via SourceTree:

fatal: path not found: $(git

Hopefully that helps narrow down what may be going on.

FURTHER UPDATE

Turns out my syntax was wrong for grabbing only the modified files from a specific commit but using msandiford's answer I came up with this batch file script that works perfectly:

setlocal enabledelayedexpansion
set output=
for /f "delims=" %%a in ('git diff-tree --no-commit-id --name-only -r %1^^') do ( set output=!output! "%%a" )
git archive -o update.zip HEAD %output%
endlocal

解决方案

Assuming you need a windows batch file, and not a bash script, here is a minimal batch file that may do what you want:

setlocal enabledelayedexpansion
set output=
for /f "delims=" %%a in ('git diff --name-only %1^^') do ( set output=!output! "%%a" )
git archive -o update.zip HEAD %output%
endlocal

It works by collecting all lines of the output of the git diff ... command into an environment variable, and then using this to perform the git archive ... operation.

Documentation for the Windows for command is here, including the /f switch. Documentation for the setlocal command is here.

这篇关于通过批处理文件中创建GIT修改文件的归档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆