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 /
. How do I change GIT's output to mirror my command line output?
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?
First, all git commands are executed in a git bash
sub-shell, which explains why you see '/
'.
A '\
' is an escape character for a bash session, which is why it is not used in any bash command output.
You would need to use a git wrapper (a git.pat set in your PATH) in order to replace any /
by \
.
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.
And replace C:\prgs\git\latest
by the path your Git is installed.
By specifying the full path for git.exe
and for sed.exe
, you are sure to use the right executable.
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 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:
[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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With