【版本管理 | Git 】Git最佳实践系列(一) —— LFS & .gitignore 最佳实践,确定不来看看?

🤵‍♂️ 个人主页: @AI_magician

📡主页地址: 作者简介:CSDN内容合伙人,全栈领域优质创作者。

👨‍💻景愿:旨在于能和更多的热爱计算机的伙伴一起成长!!🐱‍🏍

🙋‍♂️声明:本人目前大学就读于大二,研究兴趣方向人工智能&硬件(虽然硬件还没开始玩,但一直很感兴趣!希望大佬带带)

该文章收录专栏

✨--- [《深入解析机器学习:从原理到应用的全面指南》](https://blog.csdn.net/weixin_66526635/category_12216068.html) ---✨

.gitignore 最佳实践

https://github.com/github/gitignore

以上有着最全的各中项目所对应的.gitignore, 以下则是一个通用的模板

sh 复制代码
# 忽略操作系统生成的文件
.DS_Store
Thumbs.db

# 忽略编辑器和IDE生成的文件
.vscode/
.idea/
*.sublime-project
*.sublime-workspace

# 忽略编译生成的文件和文件夹
/build/
/dist/

# 忽略依赖文件夹
/node_modules/
/bower_components/

# 忽略日志文件
*.log

# 忽略临时文件
*.tmp

# 忽略系统文件
.DS_Store
desktop.ini

# 忽略压缩文件
*.zip
*.rar
*.gz

# 忽略数据库文件
*.db
*.sqlite
*.sqlite3

# 忽略IDE和编辑器配置文件
*.swp
*.swo
*.swn
*.bak

# 忽略生成的文档文件
*.html
*.pdf
*.docx

# 忽略备份文件
*.bak
*.backup

# 忽略缓存文件
.cache/

# 忽略日志文件夹
/logs/

# 忽略临时文件夹
/temp/
/tmp/

# 忽略编译器和构建工具生成的文件
.gradle/
.mvn/
target/

# 忽略Jupyter Notebook生成的文件
.ipynb_checkpoints/

# 忽略环境配置文件
.env

# 忽略IDE生成的文件
*.iml

# 忽略图片缩略图文件夹
/.thumbnails/

# 忽略本地配置文件
*.local

以下则是关于Python的

shell 复制代码
# 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/
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
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# 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
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
#   For a library or package, you might want to ignore these files since the code is
#   intended to run in multiple environments; otherwise, check them in:
# .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

# poetry
#   Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
#   This is especially recommended for binary packages to ensure reproducibility, and is more
#   commonly ignored for libraries.
#   https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
#   Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
#   pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
#   in version control.
#   https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# 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/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
#  JetBrains specific template is maintained in a separate JetBrains.gitignore that can
#  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
#  and can be added to the global gitignore or merged into this file.  For a more nuclear
#  option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

Git lfs 清空文件

要清空您的Git Large File Storage (LFS)中的所有文件,您可以按照以下步骤进行操作:

  1. 打开命令行终端或Git Bash。

  2. 导航到包含您的存储库的本地文件夹。

  3. 运行以下命令以确保您的Git LFS是最新版本:

    复制代码
    git lfs update
    ```
  4. 运行以下命令以删除LFS对象和相关引用:

    复制代码
    git lfs prune
    ```
    这将删除存储库中所有未跟踪的LFS对象。
  5. 运行以下命令以从存储库中删除LFS对象:

    复制代码
    git lfs ls-files | cut -d ' ' -f 3 | xargs git rm --cached
    ```
    这将从存储库中删除所有跟踪的LFS对象。请注意,这只会从存储库中删除跟踪,而不会删除实际的LFS对象文件。

    如果文件路径中包含空格或特殊字符,可以尝试在路径周围使用引号或双引号,例如:

    复制代码
    git lfs ls-files | cut -d ' ' -f 3 | xargs -I {} git rm --cached "{}"
    ```
    这将确保文件路径被正确地传递给`git rm --cached`命令。

    如果问题仍然存在,您可以尝试手动删除LFS跟踪的文件。运行以下命令来查看LFS跟踪的文件列表:

    复制代码
    git lfs ls-files

    然后,使用git rm --cached命令手动逐个删除文件,例如:

    git rm --cached path/to/file.ext

    请将path/to/file.ext替换为LFS跟踪文件的实际路径。重复此步骤直到删除所有LFS跟踪的文件。

  6. 运行以下命令以提交更改:

    复制代码
    git commit -m "Remove all LFS objects"
    ```
    这将创建一个提交,删除存储库中所有LFS对象的跟踪。
  7. 运行以下命令以将更改推送到远程存储库:

    复制代码
    git push origin <branch-name>
    ```
    将`<branch-name>`替换为您的分支名称。

请注意,执行上述操作将从存储库中移除所有LFS对象的跟踪,但不会删除实际的LFS对象文件。如果您希望完全删除LFS对象文件并释放存储空间,请参考Git LFS的文档或使用适当的命令来管理LFS服务器端的存储。

复制代码
						  🤞到这里,如果还有什么疑问🤞
					🎩欢迎私信博主问题哦,博主会尽自己能力为你解答疑惑的!🎩
					 	 🥳如果对你有帮助,你的赞是对博主最大的支持!!🥳
相关推荐
GISer_Jing5 小时前
Git协作开发:feature分支、拉取最新并合并
大数据·git·elasticsearch
高山莫衣11 小时前
git rebase多次触发冲突
大数据·git·elasticsearch
码农藏经阁11 小时前
工作中常用的Git操作命令(一)
git
kobe_OKOK_11 小时前
【团队开发】git 操作流程
git·elasticsearch·团队开发
码农垦荒笔记11 小时前
Git 安装闭坑指南(仅 Windows 环境)
windows·git
CC码码21 小时前
管理你的多个 Git 密钥(多平台多账号)
git·gitlab·github
CC码码21 小时前
管理你的多个 Git 密钥(单平台多账号)
git·gitlab·github
大卫小东(Sheldon)21 小时前
GIM 1.5发布了! 支持Windows系统了
git·ai·rust
flying jiang21 小时前
将大仓库拆分为多个小仓库
git
李boyang10 天前
Git(四):远程操作
git