不想自動加到git裡的檔案

使用 git status 時,會看到 「.pyc」的binary 檔案,或「.」開頭的隱藏檔,這些都不想自動加入到 git 裡。

希望 git 指令幫我們排除,只要在專案目錄裡放一個 .gitignore 檔案,並且設定想要忽略的規則就行了。如果這個檔案不存在,就手動新增它:

$ touch .gitignore

編輯這個檔案的內容:

# 檔案名稱 .gitignore

#built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

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

# Windows thumbnail db
Thumbs.db

# OSX files
.DS_Store

# Android Studio
*.iml
.idea
#.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
.gradle
build/
.navigation
captures/
output.json 

#NDK
obj/
.externalNativeBuild

#Python
*.pyc

# hidden file
.*

# vi
*~

# 忽略所有附檔名是 .tmp 的檔案
*.tmp

最後再透過下列的指令,套到所有的 git 專案,不用一個一個專案去設定 .gitignore 檔案。

There are certain files created by particular editors, IDEs, operating systems, etc., that do not belong in a repository. But adding system-specific files to the repo’s .gitignore is considered a poor practice. This file should only exclude files and directories that are a part of the package that should not be versioned (such as the node_modules directory) as well as files that are generated (and regenerated) as artifacts of a build process.

All other files should be in your own global gitignore file. Create a file called .gitignore in your home directory and add anything you want to ignore. You then need to tell git where your global gitignore file is.

Mac

git config --global core.excludesfile ~/.gitignore

Windows

git config --global core.excludesfile %USERPROFILE%\.gitignore

This will result in an entry in your .gitconfig that looks like this:

[core]
    excludesfile = {path-to-home-dir}/.gitignore

相關文章

寫留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *