我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们
文章版本: Enterprise Server 2.19

忽略文件

You can configure Git to ignore files you don't want to check in to GitHub Enterprise.

本文内容

Configuring ignored files for a single repository

You can create a .gitignore file in your repository's root directory to tell Git which files and directories to ignore when you make a commit. To share the ignore rules with other users who clone the repository, commit the .gitignore file in to your repository.

GitHub maintains an official list of recommended .gitignore files for many popular operating systems, environments, and languages in the github/gitignore public repository. 您也可以使用 gitignore.io 创建 .gitignore 文件,以用于操作系统、编程语言或 IDE。 For more information, see "github/gitignore" and the "gitignore.io" site.

  1. 打开 Terminal(终端)Terminal(终端)Git Bash
  2. Navigate to the location of your Git repository.
  3. Create a .gitignore file for your repository.

    $ touch .gitignore

For an example .gitignore file, see "Some common .gitignore configurations" in the Octocat repository.

If you want to ignore a file that is already checked in, you must untrack the file before you add a rule to ignore it. From your terminal, untrack the file.

$ git rm --cached FILENAME

Configuring ignored files for all repositories on your computer

You can also create a global .gitignore file to define a list of rules for ignoring files in every Git repository on your computer. 例如,在 ~/.gitignore_global 中创建文件并加入一些规则。

  1. 打开 Terminal(终端)Terminal(终端)Git Bash
  2. Configure Git to use the exclude file ~/.gitignore_global for all Git repositories.

    $ git config --global core.excludesfile ~/.gitignore_global

Excluding local files without creating a .gitignore file

如果不想创建 .gitignore 文件与其他人共享,可以创建不随仓库提交的规则。 您可以对不希望其他用户生成的本地生成文件使用此方法,例如编辑者创建的文件。

使用您常用的文本编辑器打开 Git 仓库根目录中的文件 .git/info/exclude。 您在此处添加的任何规则都不会检入,并且只会对您的本地仓库忽略文件。

  1. 打开 Terminal(终端)Terminal(终端)Git Bash
  2. Navigate to the location of your Git repository.
  3. 使用您常用的文本编辑器打开文件 .git/info/exclude

延伸阅读

问问别人

找不到要找的内容?

联系我们