如何使用 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:48:32  来源:igfitidea点击:

How to change folder with git bash?

gitgit-bash

提问by Sam Mitchell

My default gitfolder 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 pwdcommand 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:

以下是我遵循的步骤:

  1. In bash, check in which directory you are by using the command:

    $ pwd
    
  2. copy the URL of the directory you want to go like after using the first command (PWD) I got:

    $  /c/Users/yourUsername
    
  3. Now I want to change this to the directory of cdrive and folder MyPictures. To do that, I will go the directory of MyPictures, copy the URL, and paste it in the Git bash. However, before that:

     syntax changes in bash

    C:\MyPicturebecomes $ cd /C/MyPicture(backslashes are replaced with slashes)

  4. 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"
    
  5. Remember to change directory you just need to copy the requiredUrland paste that in bash with double-quotes like:

    cd "required URL"
    
  1. 在 bash 中,使用以下命令检查您所在的目录:

    $ pwd
    
  2. 使用PWD我得到的第一个命令 ( )后,复制您要访问的目录的 URL :

    $  /c/Users/yourUsername
    
  3. 现在我想将其更改为cdrive 和 folder 的目录MyPictures。为此,我将转到 的目录MyPictures,复制 URL,然后将其粘贴到 Git bash 中。然而,在此之前:

     bash 中的语法更改

    C:\MyPicture变成$ cd /C/MyPicture(反斜杠替换为斜杠)

  4. 如果文件夹名称有一些空格,例如(我的程序),那么您需要将其括在双引号中,例如:

    $ cd "C:\Program Files"
    
  5. 请记住更改目录,您只需要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

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)
  • The cdcommand can be memorized as "change directory".
  • 您可以使用 来检查当前文件夹pwd
  • 如果路径包含空格,则需要使用引号。( cd "/c/Program Files")

  • 在 Windows 上,您可以更改 Git Bash 的默认起始目录。

    • 右键单击git-bash.exe,选择Properties,打开Shortcuts,并将Start in:更改为您最常用的文件夹。(截图
  • cd命令可以记忆为“更改目录”。

See also

也可以看看

回答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“'打印工作目录'的首字母缩写词”。

pwd command in Linux

Linux 中的 pwd 命令

  1. 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.
  1. 有一个命令ls为我们提供有关特定目录中的文件夹和文件的信息。这是一个非常方便的命令,通常用于了解文件结构。在我的回答中,我也将利用这一点。

enter image description here

在此处输入图片说明

  1. 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.
  1. 为了沿着文件夹树遍历,我们使用了另一个非常重要的命令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. Going to child directory

3a) cd命令让我们遍历到子目录。请检查快照。 转到子目录

3b) Now to traverse back into the parent directory, we make use of cd ..command: Please check the Image below: enter image description here

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 ..会将终端指向用户文件夹。

enter image description here

在此处输入图片说明

B) Again Typing cd .. will make Terminal to point towards C Drive.

B) 再次键入 cd .. 将使终端指向 C 驱动器。

enter image description here

在此处输入图片说明

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.

和瓦拉你已经走了这么远才能到达你的目的地。恭喜。

enter image description here

在此处输入图片说明

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

光盘项目

enter image description here

在此处输入图片说明

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 cdthen copy and paste the file path.

只需键入cd然后复制并粘贴文件路径。

Example of changing directory:

更改目录示例:

example of changing directory

更改目录的示例