How do I change the directory in Git Bash with Git for Windows?

微笑、不失礼 提交于 2019-12-20 09:36:47

问题


How would I change to the directory C:/Users/myname/project name in Git Bash?


回答1:


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.




回答2:


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.

The .. represents moving 1 directory up.




回答3:


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

If I remember correctly. I do not have a windows machine.

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.)




回答4:


An alternative that worked for me (Windows 10 x64) is putting the full address in quotes:

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.




回答5:


If you are at the a directory and wanna switch to sub directory use :

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



来源:https://stackoverflow.com/questions/18288723/how-do-i-change-the-directory-in-git-bash-with-git-for-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!