git操作命令
branch操作
新建分支
| 1 | git branch v3.0.0 | 
查看分支
- 查看本地分支 - 1 - git branch 
- 查看所有分支 - 1 - git branch -a 
- 查看远端分支 - 1 - git branch -r 
删除分支
- 删除本地分支 - 1 - git branch -d feature/v1.1.0 
- 删除远端分支 - 1 
 2
 3- git branch -r -d origin/feature/v1.0.0 
 git push origin -d feature/v1.0.0
拉取\切换分支
| 1 | git checkout v3.0.0 // 获取tag | 
获取分支
| 1 | git clone git://github.com/schacon/grit.git [mygrit] | 
更新
| 1 | git fetch // 同步远端仓库到本地仓库 | 
提交代码到分支
| 1 | git status // 查看代码的修改状态 | 
还原代码到指定版本
- 使用git revert(它是新增记录)1 
 2
 3git revert -n <commit-id> // 将代码回退倒commit-id时的版本 
 git commit -m "revert xx 版本" // 提交
 git push origin <branch> // 更新服务器版本,此时服务器会多出一条修改记录
- 使用git reset(它会将HEAD移动到你reset的记录)1 
 2git reset --hand <commit-id> // 将本地代码回退到commit-id时的版本 
 git push -f// 将远端仓库更新,此时HEAD版本变为commit-id;必须使用-f,因为你本地版本比远端的旧
tag操作
- 查看tag - 1 
 2
 3
 4
 5- // 查看本地tag 
 git tag --list
 // 查看远端tag
 git ls-remote --tags
- 新建tag - 1 - git tag v3.0.0 
- 删除本地tag - 1 - git tag -d v1.0.0 
- 删除远端tag - 1 - git push origin -d tag v1.0.0 
- 将本地tags推送到远端 - 1 
 2
 3
 4
 5- // 将本地单个tag推送至远端 
 git push origin v1.0.0
 // 将本地tag全部推送至远端
 git push origin --tags
- 查看本地分支的git地址 - 1 - git remote -v 
- 更换本地分支的git地址 - 1 - git remote set-url origin http://xxx.xxx.xxx.git 
- 查看tag信息 - 1 - git show v1.0.0 
- checkout tag代码 - 1 
 2
 3
 4- // 先跟新远端tag到本地 
 git fetch --all --tags
 // checkout tag为新分支代码
 git checkout -b version2 v2.0.0
分支合并
- 合并本地分支 - 1 - git merge v1.2.0 --no-commit 
- 合并远端分支 - 1 - git merge origin v1.2.0 --no-commit 
.git 文件过大操作处理
一般不建议做此操作,因为我们公司不允许使用具有上传功能的网站,所以我们的apk是放到自己的git服务器上
供测试人员下载,久而久之这会导致git的历史记录过大(每一次记录都是apk文件),下面的介绍是用来删除git的历史记录。
| 1 | git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch <文件夹名>' | 
