bash 从 Git 开始:如何设置要在其中工作的目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15323174/
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-18 04:48:11  来源:igfitidea点击:

Starting with Git: How can I set the directory to work in?

gitbashgit-bash

提问by guypursey

Very basic beginner question on Git, from someone with very little command line experience.

关于 Git 的非常基本的初学者问题,来自几乎没有命令行经验的人。

  • I have Git Bash open.
  • I have been following this very useful guide, which I have understood up to a point.
  • I want to use git initcommand to start working in a folder.
  • 我打开了 Git Bash。
  • 我一直在关注这个非常有用的指南,我已经理解了这一点。
  • 我想使用git init命令开始在文件夹中工作。

When opening Git Bash I'm shown my username and computer name (in the form username@computername) and given a $prompt. In Windows' cmd.exe I can use commands like dirto list everything in a folder, and cdto change to a particular folder, but unless I've missed something these commands aren't available to Git Bash.

打开 Git Bash 时,我会看到我的用户名和计算机名称(以 形式username@computername)并给出$提示。在 Windows 的 cmd.exe 中,我可以使用诸如dir列出文件夹中的所有内容并cd更改为特定文件夹的命令,但除非我遗漏了某些内容,否则这些命令对 Git Bash 不可用。

QUESTION: The guide says 'if you're starting to track an existing project in Git, you need to go to the project's directory and type $ git init'. How can I list and navigate to folders where I might want to use the git initcommand in Git Bash?

问题:指南说“如果您开始在 Git 中跟踪现有项目,则需要转到项目目录并键入$ git init”。如何git init在 Git Bash 中列出并导航到我可能想要使用该命令的文件夹?

...

...

...

...

...following the answers below...

...按照下面的答案...

RESOURCES FOR OTHERS: Since getting the answers below (which helped clear up my beginner's confusion about the Bash scripting language and Git Bash), I've found the following resources which might be useful to others struggling to get started...

其他人的资源:自从得到下面的答案(这有助于解决我的初学者对 Bash 脚本语言和 Git Bash 的困惑),我发现以下资源可能对其他努力入门的人有用......

回答by Nevik Rehnel

You might want to look at a beginner's tutorial for Bash, which will teach you the basics about navigating and file manipulation you will need.

您可能想查看 Bash 的初学者教程,该教程将教您有关导航和文件操作的基础知识。

Alternatively or additionally, you can look for tutorials on how to use Git in cmd.exe or in PowerShell (it works in both, but has some quirks and takes some additional setup).

或者或另外,您可以查找有关如何在 cmd.exe 或 PowerShell 中使用 Git 的教程(它在两者中都适用,但有一些怪癖并需要一些额外的设置)。

For now, the commands you need are:

现在,您需要的命令是:

  1. lsto list a directory's contents. lsuses a short multi-column layout by default, if you want to know more about files (similar to how dirlooks by default in cmd.exe), you can use ls -la(the two options mean "long format" and "show all entries"
  2. cd(equivalent: chdir) to change the directory; it takes one argument, which is the path of the folder you want to change into; it can be absolute or relative, and must exist; difference to cmd.exe's cd: if you want to go up one level, don't forget the space (must be cd ..; cd..won't work); more examples: cd localfolder/subfolder, cd /c/absolute/path/example
  3. mkdir(there is by default nomdalias for this, though you can define it if you want) to make a directory; works like in cmd.exe: mkdir new_folder_name
  1. lsš吨目录的内容。ls默认使用短多栏布局,如果你想了解更多有关文件(类似于如何dir通过默认输入cmd.exe长相),你可以使用ls -la(这两个选项的意思是“翁格式”和“显示一个LL项”
  2. cd(当量:chdir),以CH安格的DIRectory; 它需要一个参数,即您要更改的文件夹的路径;它可以是绝对的,也可以是相对的,并且必须存在;与 cmd.exe 的 cd 不同:如果你想上一层,不要忘记空格(必须是cd ..;cd..不起作用);更多例子:cd localfolder/subfoldercd /c/absolute/path/example
  3. mkdir(有默认情况下没有md此别名,但你可以定义它,如果你想)到一个ķE中的DIRectory; 就像在 cmd.exe 中一样:mkdir new_folder_name

回答by Ronnie

use ls instead dir, cwd, chdir or cd for changing directory...

使用 ls 代替 dir、cwd、chdir 或 cd 来更改目录...

Like

喜欢

$ cd /I/want/to/go/here
$ ls
.
..
File1
File2
............
............
$ mkdir Folder1
$ cd Folder1
$ git init