1. 程式人生 > >Git 忽略規則 .gitignore文件

Git 忽略規則 .gitignore文件

computer epo ignore native guid Language hid -c source

添加忽略規則 .gitignore項目
Android

添加忽略規則的三種方式

From time to time, there are files you don‘t want Git to check in to GitHub. There are a few ways to tell Git which files to ignore.
有時候,有一些文件你不希望Git檢入GitHub。有幾種方法可以告訴Git忽略哪些文件。

局部 Create a local .gitignore

If you create a file in your repository named .gitignore, Git uses it to determine
which files and directories to ignore, before you make a commit.

如果您在存儲庫中創建一個名為【.gitignore】的文件,Git會在您進行提交之前使用它來確定忽略哪些文件和目錄。

A .gitignore file should be committed into your repository, in order to share the ignore rules with any other users that clone the repository.
一個.gitignore文件應該被提交到你的倉庫中,以便與任何其他克隆倉庫的用戶共享這個忽略規則。

GitHub maintains
an official list of recommended .gitignore files for many popular operating systems, environments, and languages in the github/gitignore public repository.

GitHub在 github/gitignore 公共倉庫中維護了一個官方的列表,(列表裏面包含了在使用)許多流行的操作系統、環境和語言時的推薦的.gitignore文件
  1. In Terminal, navigate to the location of your Git repository.

  2. Enter touch .gitignore to create a .gitignore file.
touch .gitignore
11 1
touch .gitignore

The Octocat has a Gist containing some good rules to add to this file.

If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:
如果你想忽略一個已經出於檢入狀態的文件,即使你稍後添加了一個(忽略)規則,Git也將不會忽略這個文件。在這種情況下,您必須先在終端中運行以下命令,以解除文件:
git rm --cached FILENAME  # 停止追蹤指定文件,但該文件會保留在工作區
11 1
git rm --cached FILENAME  # 停止追蹤指定文件,但該文件會保留在工作區

全局 Create a global .gitignore

You can also create a global .gitignore file, which is a list of rules for ignoring files in every Git repository on your computer. For example, you might create the file at ~/.gitignore_global and add some rules to it.
您也可以創建一個全局的.gitignore文件,這是一個忽略計算機上每個Git倉庫中文件的規則列表。例如,您可以在【~/.gitignore_global】中創建一個文件,並為其添加一些規則。
  1. Open Terminal.
  2. Run the following command in your terminal:
git config --global core.excludesfile ~/.gitignore_global
11 1
git config --global core.excludesfile ~/.gitignore_global

個人 Explicit repository excludes

explicit [?k?spl?s?t]  adj. 明確的,清楚的; 直言的; 詳述的; 不隱瞞的;
exclude  [?k‘sklu:d]  vt. 排斥;排除,不包括;驅除,趕出 
22 1
explicit [?k?spl?s?t]  adj. 明確的,清楚的; 直言的; 詳述的; 不隱瞞的;
2
exclude  [?k‘sklu:d]  vt. 排斥;排除,不包括;驅除,趕出 
If you don‘t want to create a .gitignore file to share with others, you can create rules that are not committed with the repository. You can use this technique for locally-generated files that you don‘t expect other users to generate, such as files created by your editor.
如果您不想創建一個與其他人共享的 .gitignore 文件,那麽你可以創建一些不與倉庫一起提交的規則。您可以將此技術用於不希望其他用戶生成的本地生成的文件,例如編輯器創建的文件。

Use your favorite text editor to open the file called .git/info/exclude within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository.
使用你最喜歡的文本編輯器打開Git倉庫根目錄下名為【.git/info/exclude】的文件。您在此處添加的任何規則都不會被檢入,並且只會忽略本地倉庫的文件。
  1. In Terminal, navigate to the location of your Git repository.
  2. Using your favorite text editor, open the file .git/info/exclude.

GitHub中的.gitignore項目

A collection of .gitignore templates .gitignore模板的集合
This is GitHub’s collection of .gitignore file templates. We use this list to populate the .gitignore template choosers available in the GitHub.com interface when creating new repositories and files.
這是GitHub的.gitignore文件模板的集合。當在GitHub.com中創建新的倉庫和文件時,我們使用這個列表來填充可用的.gitignore模板選擇器。

For more information about how .gitignore files work, and how to use them, the following resources are a great place to start:
  • The Ignoring Files chapter of the Pro Git book.
  • The Ignoring Files article on the GitHub Help site.
  • The gitignore(5) manual page.

【文件夾結構 Folder structure】The files in the root directory are for .gitignore templates that are project specific, such as language or framework specific templates. Global (operating system or editor specific) templates should go into the Global/ directory.
根目錄中的文件用於特定於項目的.gitignore模板,如語言或特定於框架的模板。全局(操作系統或編輯器特定)模板應該去【Global/】目錄中去找。

【貢獻指南 Contributing guidelines】We’d love for you to help us improve this project. To help us keep this collection high quality, we request that contributions adhere to the following guidelines.
我們很樂意您能幫助我們改善這個項目。為了幫助我們保持這個集合的高質量,我們要求貢獻者遵守以下準則。

後面省略一千字...

Android.gitignore

# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Intellij
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/dictionaries
.idea/libraries

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json
1
# Built application files
2
*.apk
3
*.ap_
4
5
# Files for the ART/Dalvik VM
6
*.dex
7
8
# Java class files
9
*.class
10
11
# Generated files
12
bin/
13
gen/
14
out/
15
16
# Gradle files
17
.gradle/
18
build/
19
20
# Local configuration file (sdk path, etc)
21
local.properties
22
23
# Proguard folder generated by Eclipse
24
proguard/
25
26
# Log Files
27
*.log
28
29
# Android Studio Navigation editor temp files
30
.navigation/
31
32
# Android Studio captures folder
33
captures/
34
35
# Intellij
36
*.iml
37
.idea/workspace.xml
38
.idea/tasks.xml
39
.idea/gradle.xml
40
.idea/dictionaries
41
.idea/libraries
42
43
# Keystore files
44
# Uncomment the following line if you do not want to check your keystore files in.
45
#*.jks
46
47
# External native build folder generated in Android Studio 2.2 and later
48
.externalNativeBuild
49
50
# Google Services (e.g. APIs or Firebase)
51
google-services.json
52
53
# Freeline
54
freeline.py
55
freeline/
56
freeline_project_description.json

Java.gitignore

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
22 1
# Compiled class file
2
*.class
3
4
# Log file
5
*.log
6
7
# BlueJ files
8
*.ctxt
9
10
# Mobile Tools for Java (J2ME)
11
.mtj.tmp/
12
13
# Package Files #
14
*.jar
15
*.war
16
*.ear
17
*.zip
18
*.tar.gz
19
*.rar
20
21
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
22
hs_err_pid*
2017-11-7

來自為知筆記(Wiz)

Git 忽略規則 .gitignore文件