从 cmd 转义 git config 中的双引号 [英] escape double quotes in git config from cmd

查看:32
本文介绍了从 cmd 转义 git config 中的双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个批处理文件来初始化我的 .gitconfig 文件中的所有键/值.

我在尝试从 cmd 设置以下部分时遇到问题:

[mergetool "p4merge"]cmd = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"

我试过了:

git config --global mergetool.p4merge.cmd "p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED""

但结果是:

[mergetool "p4merge"]cmd = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"

我应该如何从 cmd 中转义双引号?

解决方案

Git on Windows: How do you set 的答案一个合并工具?"建议:

<块引用>
  • 来自 git bash 会话:

git config --global mergetool.p4merge.cmd 'p4merge.exe $BASE";"$本地""$远程""$MERGED"'

<块引用>

  • 或者,从 Windows cmd.exe shell,使用 3 个双引号 """ 转义一个 ":

git config --global mergetool.p4merge.cmd "p4merge.exe """$BASE""""""$LOCAL""""""$REMOTE"""""""$MERGED""""

所以这取决于你是启动了 git-bash.bat 还是 git-cmd.bat

CMD 中的其他示例:

git config --global core.editor """"C:UsersvoncAppDataLocalProgramsMicrosoft VS CodeCode.exe"""--等等"# 或者git config --global core.editor """"C:/Program Files/Notepad++/notepad++.exe"""""

I want to create a batch file that initializes all the key/values in my .gitconfig file.

I have troubles trying to set the following section from cmd:

[mergetool "p4merge"]
    cmd = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"

I tried:

git config --global mergetool.p4merge.cmd "p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED""

But the result is:

[mergetool "p4merge"]
    cmd = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"

How should I escape that double quotes from cmd?

解决方案

The answer to "Git on Windows: How do you set up a mergetool?" proposes:

  • From a git bash session:

git config --global mergetool.p4merge.cmd 'p4merge.exe "$BASE" "$LOCAL" "$REMOTE" "$MERGED"'

  • or, from a windows cmd.exe shell, using 3 double-quotes """ to escape one ":

git config --global mergetool.p4merge.cmd "p4merge.exe """$BASE""" """$LOCAL""" """$REMOTE""" """$MERGED""""

So it depends if you launched git-bash.bat or git-cmd.bat

Other examples in CMD:

git config --global core.editor """"C:UsersvoncAppDataLocalProgramsMicrosoft VS CodeCode.exe""" --wait"
# or
git config --global core.editor """"C:/Program Files/Notepad++/notepad++.exe""""

这篇关于从 cmd 转义 git config 中的双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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