常用的.gitignore文件写法

这些条目,用到了再添加,不用一开始就添加很多条目,因为不一定用到,过早优化是万恶之源。

# 临时和备份文件
*.tmp
*.bak
*.swp
*~

# 操作系统相关
.DS_Store
Thumbs.db
ehthumbs.db

# 开发工具(IDE)
/.fleet
/.zed
/.vscode
/.settings
/.buildpath
/.project
/.idea
*.iml
*.iws
.idea_modules/
atlassian-ide-plugin.xml
crashlytics.properties
fabric.properties
.bootstrap/cache

# 构建和存储
out/
/public/build
/public/hot
/public/storage
/storage/*.key

# PHP
.phpactor.json
.phpunit.result.cache
/.phpunit.cache
.php-cs-fixer.cache
.phpstan.cache
rector.cache

# Composer
composer.lock
composer.phar
vendor/
auth.json

# npm
package-lock.json
yarn.lock
npm-debug.log
yarn-error.log
node_modules/

# Homestead开发环境
Homestead.json
Homestead.yaml

# 项目环境
.env
.env.backup
.env.production

# 日志
debug.log
error.log
*.log

# 测试
*.sqlite       # 本地测试数据库
/tests/_output # 测试输出目录


###### 操作系统文件 ######
.AppleDouble
.LSOverride
._*
.Spotlight-V100
.Trashes
.TemporaryItems
.fseventsd
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
.history

# Windows temporary files
Thumbs.db
ehthumbs.db

# Mac temporary files
.DS_Store


###### Directory for temporary files ######
.tmp/
.temp/
tmp/
temp/
caches/
cache/

modules/

###### compiled files and directories ######
*.com
*.class
*.dll
*.exe
*.o
*.so
/dist
/build


###### Download and upload directory ######
upload/
download/
uploadfiles/
downloadfiles/


###### 压缩包 ######
# Git 自带压缩,如果这些压缩包里有代码,建议解压后 commit
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

###### 日志文件和数据库 ######
*.log
*.sqlite
*.db

###### 常见IDE和编辑器 ######
*.sublime*
__debug_bin
.project
.env
.env.backup
.env.production
/.fleet
/.idea
/.vscode
/.zed
/public/build
/public/hot
/public/storage
/public/**/*.map
/storage/*.key
/vendor
/go_build_*
out/

###### 前端工具链 ######
.sass-cache/*
node_modules/
npm-debug.log
yarn-error.log


###### PyCharm ######
# Created by https://www.gitignore.io/api/pycharm
# Edit at https://www.gitignore.io/?templates=pycharm

### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn.  Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### PyCharm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/sonarlint

# End of https://www.gitignore.io/api/pycharm


###### Go ######
# `go test -c` 生成的二进制文件
*.test
# go coverage 工具
*.out
*.prof
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*


###### Python ######
# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
#   However, in case of collaboration, if having platform-specific dependencies or dependencies
#   having no cross-platform support, pipenv may install dependencies that don't work, or not
#   install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# End of https://www.gitignore.io/api/python


###### Php Laravel ######

# Created by https://www.gitignore.io/api/laravel
# Edit at https://www.gitignore.io/?templates=laravel

### Laravel ###
/vendor/
node_modules/
npm-debug.log
yarn-error.log

# Laravel 4 specific
bootstrap/compiled.php
app/storage/

# Laravel 5 & Lumen specific
public/storage
public/hot
storage/*.key
.env
Homestead.yaml
Homestead.json
/.vagrant
.phpunit.result.cache

auth.json

# End of https://www.gitignore.io/api/laravel


###### Node.js ######

# Created by https://www.gitignore.io/api/node
# Edit at https://www.gitignore.io/?templates=node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# End of https://www.gitignore.io/api/node

GitLab Web IP ≠ GitLab SSH Repo IP (and Why Your ~/.ssh/config Probably Lies to You)

The IP you get when you ping gitlab.yourcompany.com (or whatever your instance is) is almost never the actual IP that your Git remotes are talking to over SSH.

Quick way to find the real SSH host IP + port:

  1. Create a throwaway test repo on your GitLab instance
  2. Go to the repo’s “Code” button → “Clone with SSH”
  3. Copy the git@xxx line — the hostname right after the @ is your real SSH server IP (or hostname), and the port is usually right there too (often 22, but self-hosted instances love 2222, 8022, etc.)

Common mistake that bites almost everyone:

You do this in ~/.ssh/config:

Host gitlab.jhso.cn
    HostName 172.16.1.33
    User git
    Port 2222
    IdentityFile ~/.ssh/id_ed25519_jhso

Then git clone git@gitlab.jhso.cn:group/project.git fails with

fatal: unable to access ‘git@gitlab.jhso.cn:group/project.git/’: …

Why? Because ssh is connecting to whatever A/AAAA record gitlab.jhso.cn currently resolves to — which is usually the web frontend/load-balancer IP, not the actual gitaly/ssh server.

Correct way (the ugly but working way):

Host 172.16.1.33
    HostName 172.16.1.33
    User git
    Port 2222
    IdentityFile ~/.ssh/id_ed25519_jhso

And now your remotes become git@172.16.1.33:group/project.git (yes, IP as hostname in the URL — it feels dirty but it reliably bypasses the wrong DNS target).

Moral: When GitLab is self-hosted/behind weird proxies/CDNs/firewalls, trust the SSH clone URL it literally shows you, not the pretty domain you use in the browser.

gitlab网站的IP地址不一定是gitlab远程代码仓库的IP地址

gitlab网站的IP地址不一定是gitlab远程代码仓库的IP地址,如何获取远程代码仓库的真实IP地址和端口?只需在gitlab网站上创建一个测试仓库,然后在“代码”->“使用SSH克隆”界面就能看到远程仓库的真实IP地址和端口号了:

然后在~/.ssh/config文件里,不能使用gitlab网站的域名作为Host配置项的值,例如:

Host gitlab.jhso.cn
    HostName 172.16.1.33
    User git
    Port 2222
    IdentityFile ~/.ssh/id_ed25519_jhso

否则你在本地git clone远程代码仓库时,会报错说“fatal:无法访问远程代码仓库”。

应该使用远程代码仓库的真实IP地址作为Host配置项的值,例如:

Host 172.16.1.33
    HostName 172.16.1.33
    User git
    Port 2222
    IdentityFile ~/.ssh/id_ed25519_jhso

GOVCS环境变量配置哪些包使用哪个版本控制软件来下载

$go help vcs

go get命令可以运行类似git这样的版本控制命令来下载代码。这个功能对非中心化(分布式)存储的Go包生态系统很重要,可以从任意服务器下载Go包代码,但是这也有一个潜在的安全问题,例如一个恶意的服务器故意让go get下载并运行恶意代码。

为了均衡考虑功能和安全性,go get命令默认只会使用git或hg从公共服务器下载代码。但它也会使用任意知名的版本控制系统(bzr、 fossil、git、hg、svn)来从私有服务器下载代码,私有服务器的网址由GOPRIVATE环境变量给出(更多信息参见go help private命令的输出)。只使用Git或Mercurial下载公共服务器里的Go包代码的理由是,这两个版本控制系统最关注作为不受信任的服务器的客户端运行时的相关问题。相反,Bazaar、Fossil和Subversion主要用于受信任的有权限的环境,但并没有在安全性方面做好工作。

当只有直接从版本控制系统下载代码的时候,版本控制命令才会受到一点限制。当从一个代理下载模块代码时,go get使用代理协议来下载。默认情况下,go get下载公共包会从Go模块镜像站(proxy.golang.org)下载,除非遇到因法律等原因无法从该镜像站下载的公共包或者私有包。默认情况下,go get能从Bazaar、Fossil或Subversion这些版本控制系统里下载代码,也是从Go模块镜像站下载,但是通过冒一定的安全性风险使用一个定制的沙盒运行代码版本控制命令。

GOVCS环境变量可用于更改特定包(由模块或导入路径标识)的允许的版本控制系统。GOVCS环境变量在模块模式和GOPATH模式下构建包时都适用。使用模块模式时,GOVCS环境变量的值会去匹配模块路径;使用GOPATH模式时,匹配版本控制存储库的根目录对应的导入路径。

GOVCS环境变量的值的一般形式是以逗号分隔的模式匹配列表:vcslist规则。该模式匹配是一个glob模式,必须与模块或导入路径的一个或多个前导元素匹配。vcslist是允许的版本控制命令的管道分隔列表,或用“all”表示允许使用任何已知的命令,或用“off”表示禁用所有命令。请注意,如果某个模块与vcslist为“off”的模式匹配,则如果源服务器使用“mod”方案,则该模块仍可能被下载,该方案指示go命令使用GOPROXY协议下载该模块。优先使用GOVCS列表中最前面(左边)列出的匹配模式,即使后面的模式也可能匹配。

例如:

GOVCS=github.com:git,evil.com:off,*:git|hg

通过这一设置,导入路径以github.com/开头的Go模块只能使用git下载,导入路径以evil.com开头的Go模块不能被任何版本控制命令下载,其他所有包(*号匹配所有)只能使用git或hg下载。

特殊的模式”public”和”private”分别匹配公共的或私有的模块或导入路径。如果某个包路径匹配GOPRIVATE环境变量的值,那这个包就是私有的,否则就是公共的。

如果在GOVCS环境变量里没有列出任何匹配规则,go get命令就会使用它的默认规则——用GOVCS来表达就是”public:git|hg,private:all”。

要不受限制地使用任意版本控制系统下载任意Go包,使用:GOVCS=*:all

要禁用所有版本控制系统,使用:GOVCS=*:off

go env -w命令可以用来设置GOVCS环境变量的值,给未来的go命令使用。