文本编辑与 git 之间的关系

新项目关于 git 的初始化

Posted by qisanchi on

文本编辑与 git 之间的关系:

行尾序列 LF 和 CRLF 对于 git 的影响: LF 与 CRLF 是不同的字符,所以给 git 这种需要精确的字符比较来确认文件是否变化的软件带来麻烦。如果一个仓库同时拥有多种不同默认行尾序列的系统(同时使用 windows 和 linux 进行开发),那在提交时候,这个问题将会非常烦人。如果是旧仓库想要统一行尾序列,请参考这篇文章。新建仓库需要指定两个文件.gitattributes.gitignore,在文件中制定仓库规范,在提交代码的机器上也通过宣导进行规范。

这边提供两个文件的一些写法.gitattributes

# We'll let Git's auto-detection algorithm infer if a file is text. If it is,
# enforce LF line endings regardless of OS or git configurations.
* text=auto eol=lf
# Isolate binary files in case the auto-detection algorithm fails and
# marks them as text files (which could brick them).
*.{png,jpg,jpeg,gif,webp,woff,woff2} binary
# Don't include minified JS in git grep/diff output
test/mjsunit/asm/sqlite3/*.js -diff
# git lfs operate
*.exe filter=lfs diff=lfs merge=lfs -text

.gitignore

# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
core

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
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/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

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

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# 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
*.sqlite3
media/
files/
_credentials.py
.production

# Pycharm .idea folder, see following link to know which files should be ignored:
# https://www.jetbrains.com/help/pycharm/synchronizing-and-sharing-settings.html#7e81d3cb
.idea/workspace.xml
.idea/dataSources.*
.idea/tasks.xml
.idea/dictionaries/

# customize
http_cookies
json.txt
get_zhiyan/total_count.png