Is it possible to make git print back slashes instead of forward slashes when it prints out paths in a Windows console? I'd like to be able to copy the paths that it outputs and paste it into my future console commands.
Example output:
C:\vna>git status
On branch herpderp
Your branch is up-to-date with 'origin/herpyderp'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
Java/HerpDerp/src
Java/HerpDerp/src/main/java/com/derp/messaging/
Java/HerpDerp/src/main/java/com/derp/controller/event/
Java/HerpDerp/src/main/java/com/derp/controller/domain/
Java/HerpDerp/src/main/java/com/derp/controller/monitor/
nothing added to commit but untracked files present (use "git add" to track)
Instead of
Java/HerpDerp/src/main/java/com/derp/messaging/
I'd like to see
Java\HerpDerp\src\main\java\com\derp\messaging\
or even
Java\\HerpDerp\\src\\main\\java\\com\\derp\\messaging\\
Edit: I should have clarified that this was for working with git in a Windows console. Also, it seems the correct answer for my case is to use Git Bash.
Press \/ to change every backslash to a forward slash, in the current line. Press \\ to change every forward slash to a backslash, in the current line.
Windows uses backslashes for paths, while everything else seems to use forward slashes. Modern software tries to automatically correct you when you type the wrong type of slash, so it doesn't matter which type of slash you use most of the time.
If I recall correctly, backslash is used to denote something within the current computer or network such as C:\Windows or \\172.12. 1.34, while forward slashes are used to denote something that is outside or external to the current computer or network such as http://www.google.com/.
I know it's a little old, but you can use environment variable substitution to replace the /
with \
or \\
:
C:\> SET FILE=Java/HerpDerp/src
C:\> ECHO %FILE:/=\%
Java\HerpDerp\src
C:\> ECHO %FILE:/=\\%
Java\\HerpDerp\\src
C:\>
To take it a step further, you can write a batch file that does it for a command that outputs a bunch of paths: (git diff --name-only HEAD~1
in the following example)
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "usebackq delims=" %%i IN (`git diff --name-only HEAD~1`) DO (
SET FILE=%%i
ECHO !FILE:/=\!
)
ENDLOCAL
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