[英]How to execute git log on windows cmd?
I have the following command: 我有以下命令:
git log --pretty=tformat:'<li>%h %ci %d %s</li>' > changelog.html
That saves the git log to the changelog.html file. 这将git日志保存到changelog.html文件中。 When i execute it through git bash, it works fine, but when i put this code in a .bat file and run it, i get the following error:
当我通过git bash执行它时,它工作正常,但是当我将此代码放在.bat文件中并运行它时,我收到以下错误:
The system could not find the specified file
I think it's caused by the quotes on the format parameter, but i don't know how to solve the problem... Is there a way to escape the quotes maybe? 我认为这是由格式参数的引号引起的,但我不知道如何解决问题...有没有办法逃避引号呢?
Inside a Windows batch file, you have to: 在Windows批处理文件中,您必须:
%
chars. %
字符。 for them to be taken as literals >
: >
: git log --pretty=tformat:"<li>%%h %%ci %%d %%s</li>" > changelog.html
^
to escape individual characters in an unquoted string (eg, ^%
to represent literal %
, or ^|
to represent literal |
), but that wouldn't work here , because of the following caveat : ^
来转义未加引号的字符串中的单个字符(例如, ^%
表示文字%
,或^|
表示文字|
),但这不起作用 ,因为以下警告 : ^
to escape a space character in order to form a single argument with embedded whitespace; ^
来转义空格字符以形成具有嵌入空格的单个参数; for instance, foo^ bar
is still split into 2 arguments, foo
and bar
. foo^ bar
仍然分为2个参数, foo
和bar
。 Some background for readers from the Unix world : 来自Unix世界的读者的一些背景 :
for
loop) - they canNOT be used to delimit a string with embedded whitespace. for
循环) - 它们不能用于分隔具有嵌入空格的字符串。 $
in double-quoted bash strings as \\$
to prevent expansion, you have to escape %
as %%
in double-quoted strings to prevent expansions in batch files, given that an identifier enclosed in %
chars. $
双引号的bash字符串作为\\$
防止膨胀,你有逃跑%
作为%%
在双引号字符串,以防止在批处理文件的扩展 ,因为标识符括在%
字符。 (eg, %PATH%
) signifies a variable reference to expand. %PATH%
)表示要扩展的变量引用 。
cmd.exe
prompt doesn't require escaping of %
, whereas batch files do. cmd.exe
提示不需要逃逸%
,而批处理文件执行。 More specifically, %
chars. %
chars。 in an interactive command line are treated as literals, unless they are part of a variable reference to an existing variable (eg, %windir%
), in which case expansion does take place. %windir%
),在这种情况下会发生扩展。 This oddity is the reason that a for
loop must be written as for %i in ...
( one %
) on the command line, and as for %%i in ...
( two %
) in a batch file. for
循环必须写成for %i in ...
( 一个 %
)在命令行上,并作为for %%i in ...
( 二 %
在批处理文件)。 ~
parameter modifier can be used to strip them ; ~
参数修饰符可用于剥离它们 ; eg, %~1
returns the 1st argument without double quotes (if any). %~1
返回没有双引号的第一个参数(如果有的话)。 \\
-escaping individual characters in an unquoted string in a POSIX shell is ^
-escaping , but, as stated, ^
cannot be used to escape a space in order to form a single argument with embedded whitespace. \\
在一POSIX壳没有引号的字符串-escaping 各个字符是^
-escaping,但是,如上所述, ^
不能使用,以形成带有嵌入空白一个参数逸出的空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.