GIT的基本操作(建立自己的git遠程倉庫)

先在遠程主機建立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 [email protected]:/目錄/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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章