文章目录
先在远程主机建立git仓库
git init --bare xxx.git
建立一个用户用来管理git
useradd git
passwd git
进入git仓库,建立不用更新的文件(.gitignore)
vim .gitignore
# pycharm
.idea/
*.iml
*.zip
*.csv
*.pk
*.pt
# 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/
*.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
.mypy_cache/
# .mp4
videos/
Videos/
将xxx.git仓库的文件权限全部改为git
cd (到xxxgit的上一层目录)
chown git:git -R xxx.git
git操作
远程克隆到本地
git clone git@xxx.xxx.xxx.xxx:/目录/xxx.git
本地建立新文件后提交
进本地仓库
git add .
git commit -m "这里写更新说明"
- git add {文件名} :表示指定文件
- git add . :表示当前目录所有文件
本地仓库推到远程仓库
git push origin master
本地仓库更新
git pull origin master
查看当前仓库状态
git status
查看当前提交的日志
git log
回滚
git reset --hard HEAD^
上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100
查看所有提交的日志
git reflog
删除仓库文件
git rm test.txt
创建ssh秘钥
ssh-keygen -t rsa -C 用户a
把id_rsa.pub的公钥复制进远程主机.ssh/authorized_keys
替换远程仓库
git remote -v #查看远端地址
git remote #查看远端仓库名
git remote set-url origin https://gitee.com/xx/xx.git (新地址)
gitignore不起作用
-
- 进入项目路径
-
- 清除本地当前的Git缓存
git rm -r --cached .
- 清除本地当前的Git缓存
-
- 应用.gitignore等本地配置文件重新建立Git索引
git add .
- 应用.gitignore等本地配置文件重新建立Git索引
-
- (可选)提交当前Git版本并备注说明
git commit -m 'update .gitignore'
- (可选)提交当前Git版本并备注说明