1. Git的配置
git config --global user.name "xx" // 配置此Git的使用者
git config --global user.email "xx" //配置此Git的邮箱
2. 创建git仓库
git init
3. 查看修改,并提交
git status
git add .
git commit -m "xx"
4.查看所有提交记录
git log
git reflog //比上一种方式更全
5 分支操作
git branch xx 创建分支
git checkout xx 切换分支
git checkout -b xx 创建分支并切换(上两步的结合)
git branch -d xx 删除分支
git branch -a 查看所有分支
6. 临时存储此次修改(不同于commit,它不会生成一次提交记录)
git stash 备份此次代码
git stash pop 恢复备份
git stash list 所有备份记录
git stash clear 清楚备份记录
7. 将其他分支的提交合并到当前分支
git cherry-pick xx // xx: commit id
8.将本地多次提交合并
git rebase -i xx // "xx" : commit id
git rebase --abort // 中断这次的合并
9.分支合并
git merge --no-ff xx // 保留每条分支的commit 记录合并
10. 取消某次提交所做的改变(此之前之后的commit记录保留)
git revert xx // "xx" : commit id
11. 从当前版本代码向后回滚
git reset --hard head^ //向后回滚一个版本
git reset --hard head^^ //向后回滚两个版本
git reset --hard head~10 //向后回滚10个版本
git reset --hard xx //向后回滚到此commit id所处的版本
12. 生成公钥与git服务器账号绑定
a. ssh-keygen -t rsa -C "your email"
b. 配置生成的公钥存放位置(直接回车,则是选择默认位置)
c. 找到公钥文件,复制其中的内容
d. 进入git服务器个人中心配置(点击头像-Setting-SSH and GPG keys)
13. 拉取git服务器代码
git clone git@github.com:xx/learngit.git
14. 将本地仓库与远程仓库关联
git remote add origin git@github.com:xx/learngit.git
git push -u origin master
15. 查看远程仓库所有分支
git remote -v
16.更换关联的远程仓库
git remote set-url origin
git@github.com:xx/learngit.git
17.将远程仓库最新代码更新到本地
git pull
18.将本地代码更新到远程
git pull
git push
19.将本地新建分支更新到远程
git push origin xx
20.将本地分支与远程其他分支绑定
git branch --set-upstream-to=origin/xx
21.发版代码版本Tag相关
git tag -a xx 打tag
git tag 查看tag
git checkout xx 切换代码版本
git show xx 查看该tag的详细信息
网友评论