如何向.gitignore 添加内容?

How to add content to .gitignore?

我正在读 Ethan Brown 的一本书 Learning JavaScript。在第 2 章,作者将开始描述和教授如何使用一些在整个课程中学习起来很有趣的工具。其中之一是 git.

有这部分他告诉我添加。git忽略并向其中添加一些内容。

但我还没有找到一种不会引发错误的方法。文章内容如下:

First, from your project root, initialize a repository:

$ git init

This will create a project repository for you (there’s now a hidden directory called .git in your project root).

Inevitably, there will be some files you never want tracked in version control: build artifacts, temporary files, and the like. These files can be explicitly excluded in a file called .gitignore. Go ahead and create a .gitignore file now with the following contents:

# npm debugging logs
npm-debug.log*

# project dependencies
node_modules

# OSX folder attributes
.DS_Store

# temporary files
*.tmp
*~

我能够创建 git 初始化程序。那很简单。但是从那以后事情就变得有点复杂了。

我尝试从 sully6768 提供的资源中添加 .gitignore 文件 -> How to create .gitignore file

它奏效了。但是我无法将内容提交给 .gitignore.

我的问题几乎是...

如何使用 Linux 终端 使下面的部分工作。

Go ahead and create a .gitignore file now with the following contents:

# npm debugging logs
npm-debug.log*

# project dependencies
node_modules

# OSX folder attributes
.DS_Store

# temporary files
*.tmp
*~

我不知道该怎么做。

提前致谢。

调查的其他来源:

  1. Adding files to gitignore
  2. Add .gitignore to gitignore
  3. add #*# glob to .gitignore?
  4. How to create .gitignore file

引用自:学习JavaScript 通过伊桑·布朗 版权所有 © 2015 O'Reilly Media。版权所有。 在美利坚合众国印刷。 由 O'Reilly Media, Inc. 出版,1005 Gravenstein Highway North, Sebastopol, CA 95472。

.gitignore 就像其他普通文件一样。用你喜欢的任何文本编辑器打开它(记事本,sublime text,atom,vs code,...)。然后复制书中告诉你复制的文本,然后粘贴到那个 .gitignore 文件中。

我看到我可以回答我的问题,前提是我已经得出结论,即我提出的问题的最佳方法是什么。为了不留下另一个未回答的问题。所以我开始了:

Minh 先生提供的答案实际上并没有错,但它没有提供 OP(我)想要的,即创建 .gitignore 文件并使用终端在文件中添加这些功能。为了在 Debian9 中执行此操作,您应该:

  1. 打开终端
  2. cd 到所需文件夹
  3. 使用 cat > 创建 .gitignore 文件。

这就是它的工作方式。

导航到所需的文件夹后,您将使用 cat > .gitignore,这样您就可以在其中写入任何内容。像这样...

完成后,您只需按 ctrl c(在 Debian9 上),文件就会创建并保存所需的信息。

有关如何使用 cat > 创建文件的更多信息,请按照下面的 link 进行操作。

How to quickly Create a Text File using the command Line in Linux by Walter Glen