如何使用 git bash 更改文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8961334/
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 to change folder with git bash?
提问by Sam Mitchell
My default git
folder is C:\Users\username\.git
.
我的默认git
文件夹是C:\Users\username\.git
.
What command should I use to go into C:/project
?
我应该使用什么命令进入C:/project
?
回答by Bob Fanger
The command is:
命令是:
cd /c/project/
Tip:
Use the pwd
command to see which path you are currently in, handy when you did a right-click "Git Bash here..."
提示:
使用pwd
命令查看您当前所在的路径,当您右键单击“Git Bash here...”时很方便
回答by seyi aka architect
Go to the directory manually and do right click → Select 'Git bash' option.
手动转到目录并右键单击→选择“Git bash”选项。
Git bash terminal automatically opens with the intended directory. For example, go to your project folder. While in the folder, right click and select the option and 'Git bash'. It will open automatically with /c/project
.
Git bash 终端会自动打开目标目录。例如,转到您的项目文件夹。在文件夹中,右键单击并选择选项和“Git bash”。它将自动打开/c/project
。
回答by Prateek Gangwal
Here are the steps I followed:
以下是我遵循的步骤:
In bash, check in which directory you are by using the command:
$ pwd
copy the URL of the directory you want to go like after using the first command (
PWD
) I got:$ /c/Users/yourUsername
Now I want to change this to the directory of
c
drive and folderMyPictures
. To do that, I will go the directory ofMyPictures
, copy the URL, and paste it in the Git bash. However, before that:C:\MyPicture
becomes$ cd /C/MyPicture
(backslashes are replaced with slashes)if the folder name is having some spaces like (my program) then you need to enclose it in double quotes like:
$ cd "C:\Program Files"
Remember to change directory you just need to copy the
requiredUrl
and paste that in bash with double-quotes like:cd "required URL"
在 bash 中,使用以下命令检查您所在的目录:
$ pwd
使用
PWD
我得到的第一个命令 ( )后,复制您要访问的目录的 URL :$ /c/Users/yourUsername
现在我想将其更改为
c
drive 和 folder 的目录MyPictures
。为此,我将转到 的目录MyPictures
,复制 URL,然后将其粘贴到 Git bash 中。然而,在此之前:C:\MyPicture
变成$ cd /C/MyPicture
(反斜杠替换为斜杠)如果文件夹名称有一些空格,例如(我的程序),那么您需要将其括在双引号中,例如:
$ cd "C:\Program Files"
请记住更改目录,您只需要
requiredUrl
使用双引号将其复制并粘贴到 bash 中,例如:cd "required URL"
Note:URL required with slashes.
注意:需要带斜杠的 URL。
回答by Tanaka Tsoka
pwd
: to check where you are (If necessary)
pwd
:检查你在哪里(如有必要)
cd
: change directory
cd
: 改变目录
In your case if I understand you, you need:
在你的情况下,如果我理解你,你需要:
cd c/project
回答by Stevoisiak
How to change folders in Git Bash
如何在 Git Bash 中更改文件夹
As Bob mentioned, you can change directories with cd
:
cd /c/project
If you have a Windows path with backslashes, enclose the path in single quotes:
如果您有带反斜杠的 Windows 路径,请将路径用单引号括起来:
cd 'C:\project'
Or double quotes:
或双引号:
cd "C:\project"
Tips
提示
- You can check the current folder with
pwd
. If the path contains spaces, you will need to use quotation marks. (
cd "/c/Program Files"
)On Windows, you change the default starting directory for Git Bash.
- Right click
git-bash.exe
, select Properties, open Shortcuts, and change Start in:to your most commonly used folder. (screenshot)
- Right click
- The
cd
command can be memorized as "change directory".
- 您可以使用 来检查当前文件夹
pwd
。 如果路径包含空格,则需要使用引号。(
cd "/c/Program Files"
)在 Windows 上,您可以更改 Git Bash 的默认起始目录。
- 右键单击
git-bash.exe
,选择Properties,打开Shortcuts,并将Start in:更改为您最常用的文件夹。(截图)
- 右键单击
- 该
cd
命令可以记忆为“更改目录”。
See also
也可以看看
- ss64 - Bash CD command
- Stack Overflow - Forward slash vs backward slash for file path in git bash
- ss64 - Bash CD 命令
- 堆栈溢出 - git bash 中文件路径的正斜杠与反斜杠
回答by Lanquo
From my perspective, the fastest way to achieve what you're looking for is to change "Start in" value.
从我的角度来看,实现您正在寻找的最快方法是更改“开始”值。
To do that, right-click on git-bash.exe
, go to Propertiesand change Start Invalue to the folder you want.
为此,请右键单击git-bash.exe
,转到“属性”并将“开始于”值更改为您想要的文件夹。
回答by Imran Rafiq Rather
Your Question is :
你的问题是:
My default git folder is C:\Users\username.git
我的默认 git 文件夹是 C:\Users\username.git
But I want to go into c:/project
但我想进入 c:/project
What command do I need to get into that?
我需要什么命令才能进入它?
Since you have asked primarily about gitbash which is Linux based (Terminal), there are differences in commands when compared with Command Prompt of Windows. We'll discuss gitbash (Terminal) commands only.
由于您主要询问基于 Linux(终端)的 gitbash,因此与 Windows 的命令提示符相比,命令存在差异。我们将只讨论 gitbash(终端)命令。
1.First of all we must understand that command line(In Windows) and Terminal(In Mac) always points to some folder on storage Drives .
1.首先我们必须明白命令行(在Windows中)和终端(在Mac中)总是指向存储驱动器上的某个文件夹。
To check towards what directory it is pointing to at any given time.You need to type the command: pwd"an acronym for 'Print Working Directory' ".
在任何给定时间检查它指向的目录。您需要输入命令:pwd“'打印工作目录'的首字母缩写词”。
- There is a command lswhich gives us information about the folders and files in a particular directory. This is quite a handy command and often used to know about the file structure. In my answer I will make use of this also.
- 有一个命令ls为我们提供有关特定目录中的文件夹和文件的信息。这是一个非常方便的命令,通常用于了解文件结构。在我的回答中,我也将利用这一点。
- To traverse along the folder tree we make use of yet another very important command know as cdwhich stands for change directory. And your question has the answer within this cdcommand only.
- 为了沿着文件夹树遍历,我们使用了另一个非常重要的命令cd,它代表更改目录。你的问题只有在这个cd命令中才有答案。
Here are some of the ways to traverse along the folder tree:
以下是沿文件夹树遍历的一些方法:
3a) cd command let's us traverse to child directory. Kindly check the snapshot.
3b) Now to traverse back into the parent directory, we make use of cd ..command: Please check the Image below:
3b) 现在要遍历回父目录,我们使用cd ..命令: 请检查下图:
By Using the above two steps we can easily solve your Query:
通过使用以上两个步骤,我们可以轻松解决您的查询:
A) Currently you are in : C:\Users\username.git
A) 目前你在:C:\Users\username.git
So, doing cd ..will point the Terminal towards Usersfolder.
因此,执行cd ..会将终端指向用户文件夹。
B) Again Typing cd .. will make Terminal to point towards C Drive.
B) 再次键入 cd .. 将使终端指向 C 驱动器。
C) Now doing lsat this point will let you know about all the folders and files in C drive.
C) 现在执行ls会让你知道 C 盘中的所有文件夹和文件。
Check if there is a projectfolder, Then simply for the last time type the command:
检查是否有项目文件夹,然后只需最后一次键入命令:
cd project
光盘项目
And Walla you are have traveled so far to reach to your destination. Congratulations.
和瓦拉你已经走了这么远才能到达你的目的地。恭喜。
Note:If the projectfolder is not created with C drive, simply write the command mkdir projectand it will be created. Then follow the above steps to play around.
注意:如果项目文件夹不是用C盘创建的,直接写命令mkdir project就可以创建了。然后按照上面的步骤来玩。
4) There is one more straight forward quick solution to your problem in particular:
4)特别是有一种更直接的快速解决方案可以解决您的问题:
Wherever the terminal is pointing. Simply write the command:
终端指向的任何地方。简单写下命令:
4a) cd /It will point to default root folder.
4a) cd /它将指向默认的根文件夹。
Then type the command : cd /c/to point towards c directory. Then simply go to child directory, which in your case is projectdirectory by typing:
然后键入命令:cd /c/指向 c 目录。然后只需通过键入以下内容转到子目录,在您的情况下是项目目录:
cd project
光盘项目
And you are good to go: ENJOY :)
你很高兴去:享受:)
回答by Eli
Right clicking a specific folder can help ease your pain than just by typing the whole directory. Right click + clicking s or Right click and then click "GIT bash here"
右键单击特定文件夹可以帮助减轻您的痛苦,而不仅仅是键入整个目录。右键单击 + 单击 s 或右键单击,然后单击“GIT bash here”
Hope this seems helpful
希望这看起来有帮助
回答by androminor
For the fastest way $ cd "project"
最快的方式 $ cd "project"
回答by Tasha Chetwynd
Simply type cd
then copy and paste the file path.
只需键入cd
然后复制并粘贴文件路径。
Example of changing directory:
更改目录示例: