安装:
在:
https://git-scm.com
,git的官网下载电脑对应的安装包,按默认安装。安装完以后打开git bash。
配置用户信息:
git config --global username "自己定义的用户名" | 用户名 |
git config --global email.name "XXXX@qq.com" | 邮箱 |
创建版本库
git init | 进入相应文件夹,执行此命令,创建本地仓库 |
git add filename | 文件提交到仓库,你可以多次add不同的文件 |
git commit -m "本次提交的说明" | 文件提交到仓库,commit可以一次提交很多文件 |
时光穿梭:
git diff | 查看有没有修改的内容 |
git log | 查看版本信息的详细信息<head>表示当前版本,最新提交的 |
git log --pretty=oneline | 查看基础的版本信息 |
git reset --hard HEAD^ | 回到上一个版本,用git log查看的话,最新的版本看不见了(上上一个HEAD^^) |
git reset --hard 1125252 | 数字为那个版本对应的commitId |
git reflog | 记录每一次命令 |
远程仓库:
1、创建SSH Key:
- 存在:在用户主目录下,查看有没有.ssh文件,查看文件夹下面有没有id_rsa(私钥)不能泄露出去和id_rsa.pub(公钥)文件。
- 不存在:ssh-keygen t rsa -c "xxxxx@qq.com"
默认名称:origin
master分支是主分支,时刻要与远程同步。
dev分支是开发分支,团队成员都需要在上面工作,也需要与远程同步。
bug分支,除非老板要查看米修复了几个bug。
feature分支,是否推送取决于你和你的小伙伴合作在上面开发。
远程库里面包含:README, LICENSE, .gitignore.
git clone git@github.com:sevencorn/bootstrap.git | 把项目克隆到自己的仓库里面 |
git remote | 查看远程库的信息 |
git remote -v | 显示更信息的信息,查看远程仓库地址 |
git push origin master | 把master分支上所有本地提交推送到远程库上 |
git status | 状态查询命令 |
分支管理
git checkout -b <name> | 创建分枝dev,并切换到它 |
git branch | 查看当前分支,带*号的表示当前分支 |
git branch <name> | 创建分支 |
git checkout <name> | 切换分支 |
git checkout -b <name> | 创建并切换到分支 |
git merge <name> | 合并某分支到当前分支 |
git branch -d <name> | 删除分支 |
git branch -D <name> | 强行删除,在分支没有被commit之前 |
Bug分支
git stash | 把当前工作现场“储藏”起来 |
git stash list | stash的列表 |
git stash apply | 恢复之前的工作,stash内容不删除 |
git stash drop | 恢复的同时把stash内容也删除了 |
git stash drop | 手动删除 stash |
git stash apply stash@{0} | 恢复指定的stash |
标签
git tag <v1.0> | 新建一个标签 |
git tag -1 <tagname> -m "describle" | 指定标签信息 |
git tag -s <tagname> -m "describle" | 用PGP签名标签 |
git tag | 查看所有标签 |
git show v0.9 | 查看标签信息 |