Git操作指令
一、安装git
1、设置配置信息:
git config --global user.name "Your username"
git config --global user.email "Your email"
git config --global color.ui true
git config --global alias.<别名> <原指令>
2、查看git版本号
git -v
git --version
3、查看配置信息:
git config --list
git config -l
二、创建版本库
git init
git add <file...>
git add .
git commit -m "提交描述信息(根据自己的提交写)"
三、回退撤销
1、状态日志对比
git status
git diff <file...>
git diff HEAD -- <file...>
git log [... 可带参数]
git log --pretty=oneline
git log --graph --pretty=oneline --abbrev-commit
git reflog
2、版本回退
git reset --hard HEAD^
git reset --hard <commit_id>
3、撤销修改
git checkout -- <file...>
git reset HEAD <file...>
git checkout -- <file...>
4、删除操作
git rm <file...>
git rm --cached <file...>
四、远程仓库
git remote add origin <url>
git push -u origin <name>
git push origin <name>
git remote -v
git remote rm origin
git clone <url>
git remote
git checkout -b dev origin/dev
git branch --set-upstrem-to=origin/dev dev
git push -u origin <local_branch_name>
git push -u origin <local_branch_name>:<remote_branch_name>
git push origin --delete <branch-name>
git push origin -d <branch-name>
五、分支管理
1、创建合并分支,切换分支
git checkout -b <name>
git branch <name>
git checkout <name>
git switch -c <name>
git switch <name>
git branch
git merge <name>
git branch -d <name>
2、解决冲突
# 合并后若是文件有冲突,需要手动修改再次提交
3、储存
git stash
git stash list
git stash apply
git stash apply stash@{n}
git stash drop
git stash pop
git cherry-pick <commit_id>
4、rebase
git rebase
六、Tag标签
1、创建标签
git tag <version>
git tag <version> <commit_id>
git tag -a <version> -m "描述信息" <commit_id[想要给标签设置给哪一个标签]>
git tag
git show <version>
2、操作标签
git tag -d <version>
git push origin <version>
git push origin --tags
git tag -d <version>
git push origin :refs/tags/<version>