How to change git directory separator?

When working on the Windows command line, all my paths are indicated by backslash directors-directors \ , when using GIT commands, all paths use forwardslash / instead. How to change GIT output to display my command line output?

An example of inconsistent catalog indicators;

 D:\git\demo>git status --s A test/subdir/foo.txt 
+7
git windows command-line-interface
source share
2 answers

How do I change the output of GIT to reflect the output of my command line?

First, all GIT commands are executed in the git bash sub-shell, which explains why you see " / ". " \ " is an escape character for a bash session, so it is not used in any of the output bash commands.

You will need to use the GIT shell (git.pat set in your PATH) to replace any / with \ .

git.bat :

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

Make sure git.bat installed before git.exe in your %PATH% : type where git to check the order in which git (s) are found.
And replace C:\prgs\git\latest with the path where your GIT is installed.

Having set the full path for git.exe and for sed.exe , you will definitely use the correct executable file.

+3
source share

Since what you are looking for does not seem to be specifically “how to make Git use \ in the file path”, but rather “how to make Git generate file paths with \ ", you can output via sed (which is packaged in Git Bash ) in the following way:

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

and so as not to type sed every time you can set up a Git alias to do this for you:

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

which will allow you to do this:

 $ git ws M dir\file.py ?? dir\input001.txt ?? dir\output001.txt 
+1
source share

All Articles