Git版本控制的基本命令
GIT的基本命令
创建和使用git ssh key
首先设置git的user name和email:
git config --global user.name "xxx"git config --global user.email "xxx@gmail.com"
查看GIT配置
git config --list
然后生成SSH秘钥
生成密钥:
ssh-keygen -t rsa -C "xxx@gmail.com"
按3个回车,密码为空这里一般不使用密钥。
最后得到了两个文件:id_rsa和id_rsa.pub
创建版本库
git clone <url>#克隆一个远程版本库git init#初始化本地版本库修改和提交
git status#查看状态git diff#查看变更内容git add .#添加文件git add <file>#添加指定文件git mv <old> <new>#修改文件名git rm --cached <file>#停止跟踪文件但不删除git commit -m "xxx"#提交更新的文件git commit --amend#修改最后一次提交
查看提交历史
git log#查看提交历史git log -p <file>#查看指定文件的提交历史git blame <file>#以列表方式查看指定文件提交历史
版本回退
git reset --hard HEAD#撤销工作目录中所以未提交git reset --hard HEAD^#回退到上一版本,多个版本写成HEAD~10git reset --hard 3628164#回退指定版本git checkout HEAD <file>#撤销指定未提交文件的修改内容git revert <commmit>#撤销指定提交
分支,标签
git branch#显示所有分支git checkout -b <branch>#创建并切换checkout <branch/tag>#切换到指定分支或标签git branch <new branch>#创建分支git branch -d <branch>#删除分支git tag#列出所有标签git tag <tagname>#基于最新提交创建标签git tag -d <tagname>#删除标签
分支合并
git merge <branch>#合并指定分支到当前分支git rebase <branch>#衔合指定分支到当前分支
远程仓库
git remote -v#查看远程仓库git remote show <remote>#查看远程仓库信息git remote add <remote> <url>#添加远程仓库git remote rename <old> <new>#重命名远程仓库git remote rm <remote>#删除远程仓库git remote set-url <remote> <url>#变更远程仓库地址git fetch <remote>#从远程仓库获取代码git pull <remote> <branch>#拉去代码git push <remote> <branch>#推送代码git push <remote> :<branch/tag>#删除远程分支或标签git push --tags#推送所有分支
- 上一篇: Linux 用户,组 管理
- 下一篇: chmod ,chown ,chgrp 命令