记录记录Git 常用指令大全
Yuban前言
Git 是一个开源的分布式版本控制系统,常用于代码版本管理和团队协作开发。本文将介绍一些日常开发中最常用的 Git 指令,帮助你快速上手和查阅。
一、Git 基本配置
1 2 3 4 5 6 7 8
| git config --global user.name "你的用户名"
git config --global user.email "你的邮箱@example.com"
git config --list
|
二、项目初始化与克隆
1 2 3 4 5 6 7 8
| git init
git clone https://github.com/用户名/项目名.git
git clone https://github.com/用户名/项目名.git myproject
|
三、常用工作流命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| git status
git add 文件名 git add .
git commit -m "提交说明"
git commit -am "提交说明"
git log
git log --oneline
git show
git checkout -- 文件名
git reset HEAD 文件名
|
四、分支操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| git branch
git branch 分支名
git checkout 分支名
git checkout -b 分支名
git branch -d 分支名
git merge 分支名
git add 冲突文件 git commit -m "解决冲突"
|
五、远程操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| git remote -v
git remote add origin 仓库地址
git push -u origin master
git push
git pull
git fetch
|
六、标签操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| git tag v1.0
git tag -a v1.0 -m "版本说明"
git tag
git push origin v1.0
git tag -d v1.0
git push origin :refs/tags/v1.0
|
七、撤销与恢复操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| git reset --soft HEAD~1
git reset --hard HEAD~1
git reset --hard
git diff 提交ID
git commit --amend
|
八、忽略文件配置(.gitignore)
创建 .gitignore
文件以指定 Git 忽略哪些文件:
1 2 3 4 5 6 7 8
| node_modules/
*.log
.env.local
|
九、常见问题解决
1 2 3 4 5
| git pull origin master --allow-unrelated-histories
git commit --amend -m "新的提交信息"
|
⚠️ 免责声明:本文仅供个人学习与技术研究使用。