简体   繁体   English

如何更改git目录分隔符?

[英]How to change the git directory delimiter?

When working inside a windows command prompt, all of my paths indicate director separators with a backslash \\ , when using GIT commands, all of the paths are instead using forwardslash / . 在Windows命令提示符下工作时,我的所有路径都指示导向器分隔符带有反斜杠\\ ,当使用GIT命令时,所有路径都使用forwardslash / How do I change GIT's output to mirror my command line output? 如何更改GIT的输出以镜像我的命令行输出?

Example inconsistent directory indicators; 示例不一致的目录指示符;

D:\git\demo>git status --s
A  test/subdir/foo.txt

How do I change GIT's output to mirror my command line output? 如何更改GIT的输出以镜像我的命令行输出?

First, all git commands are executed in a git bash sub-shell, which explains why you see ' / '. 首先,所有git命令都在git bash子shell中执行,这解释了为什么你看到' / '。 A ' \\ ' is an escape character for a bash session, which is why it is not used in any bash command output. ' \\ '是bash会话的转义字符,这就是为什么它不在任何bash命令输出中使用。

You would need to use a git wrapper (a git.pat set in your PATH) in order to replace any / by \\ . 您需要使用git包装器(在PATH中设置git.pat)才能替换任何/ by \\

git.bat : git.bat

C:\prgs\git\latest\bin\git.exe %*|C:\prgs\git\latest\usr\bin\sed.exe -e 's:/:\\\\:'

Make sure git.bat is set before git.exe in your %PATH% : type where git to check the order in which git(s) are discovered. 确保git.bat%PATH% git.exe 之前设置:键入where git以检查git(s)被发现的顺序。
And replace C:\\prgs\\git\\latest by the path your Git is installed. 并通过安装Git的路径替换C:\\prgs\\git\\latest

By specifying the full path for git.exe and for sed.exe , you are sure to use the right executable. 通过指定git.exesed.exe的完整路径,您一定要使用正确的可执行文件。

Since what you're looking for seems to be not specifically "how do I make Git use \\ in file paths" but rather "how do I make Git generate file paths with \\ ", you can pipe the output through sed (which is packaged in Git Bash) like so: 因为你正在寻找的东西似乎不是“如何让Git在文件路径中使用\\ ”,而是“我如何让Git用\\生成文件路径”,你可以通过sed管道输出(它是打包的)在Git Bash中)像这样:

$ git status --s | sed 's/\//\\/g'
 M dir\file.py
?? dir\input001.txt
?? dir\output001.txt

and to avoid typing sed every single time you can configure a Git alias to do it for you: 并且为了避免每次都键入sed你可以配置一个Git别名来为你做:

[alias]
    ws = "!ws() { : git status ; git status --short $@ | sed 's/\\//\\\\/g' ; } && ws"

which will let you do this: 这将让你这样做:

$ git ws
 M dir\file.py
?? dir\input001.txt
?? dir\output001.txt

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

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