Linux 如何使用 Windows 版 Git 更改 Git Bash 中的目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18288723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I change the directory in Git Bash with Git for Windows?
提问by Mihir
How would I change to the directory C:/Users/myname/project name
in Git Bash?
我将如何更改到C:/Users/myname/project name
Git Bash 中的目录?
采纳答案by Stefan N?we
cd /c/users/myname/project\ name
Beware that ls /
, or typing cd /
followed by Tab-completion, might not show the existence of this folder, but cd /c
will still work. Also note that pwd
(to print the current working directory) might show something like /bin
, but this might not be the actual working folder for commands such as git clone
, which might use the folder from which Git Bash was started.
请注意ls /
,或键入cd /
后跟 Tab 完成,可能不会显示此文件夹的存在,但cd /c
仍然有效。另请注意,pwd
(打印当前工作目录)可能会显示类似/bin
,但这可能不是诸如 之类的命令的实际工作文件夹git clone
,它可能使用启动 Git Bash 的文件夹。
回答by vgoff
You will need to use quotes in your directory name, or the short version of the filename.
您需要在目录名或文件名的简短版本中使用引号。
You can find the short version of the file name by issuing the command:
您可以通过发出以下命令找到文件名的简短版本:
dir /x
目录/x
If I remember correctly. I do not have a windows machine.
如果我没记错的话。我没有 Windows 机器。
It is a version of bash
shell though, so you should be able to simply quote it. (And the dir /x
may or may not work.)
bash
不过,它是shell 的一个版本,因此您应该能够简单地引用它。(而且dir /x
可能会或可能不会起作用。)
回答by datalifenyc
If the you know how many levels up from your current working directory, you could use cd ../project/name
to avoid writing the entire directory path.
如果您知道当前工作目录有多少级别,则可以使用cd ../project/name
以避免编写整个目录路径。
The ..
represents moving 1 directory up.
的..
表示移动1个目录起来。
回答by BruceWayne
An alternative that worked for me (Windows 10 x64) is putting the full address in quotes:
对我有用的替代方法(Windows 10 x64)是将完整地址放在引号中:
cd "D:\BWayne\Documents\- School\Developer\-- Backend\Test for GitBash"
I could then do like mkdir
, touch
, etc and it successfully put them in the Test for GitBash
folder.
然后我可以做 like mkdir
,touch
等,它成功地把它们放在Test for GitBash
文件夹中。
回答by Amin Mohamed
If you are at the a directory and wanna switch to sub directory use :
如果您在 a 目录并想切换到子目录,请使用:
cd "project name"
If you wanna go to a different path use the whole path :
如果您想转到不同的路径,请使用整个路径:
cd "C:/Users/myname/project name"
But you can avoid use white spaces in project files and folders and instead use underscore
但是您可以避免在项目文件和文件夹中使用空格,而是使用下划线