Gerrit的push
需加上分支,如为master分支提交则为:
git push origin HEAD:refs/for/master
简单点说,就是refs/for/mybranch
需要经过code review之后才可以提交;
refs/heads/mybranch
不需要code review
遇到合并失败提示:
Project policy requires all submissions to be a fast-forward.
Please rebase the change locally and upload again for review.
解决:去Gerrit页面点击rebase按钮
查看远程分支 -a(or -av),前面带*号的代表你当前工作目录所处的分支
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/release-2.0.3
remotes/origin/release-2.0.4
remotes/origin/release-2.1.0
查看本地分支
$ git branch
* master
创建分支
$ git branch test
$ git branch
* master
test
下载远程分支
选择一个非master的分支,如dev分支,修改里面的代码
$ git branch dev remotes/origin/dev #先将远程gitlab上创建的分支在本地别名化
$ git checkout dev #使用git checkout命令切换到dev分支下
将分支推到远程分支
git push origin test
切换分支
$ git checkout test
Switched to branch 'test'
$ git branch
master
* test
shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.2)
$ git branch
* br-2.1.2.2
master
test
shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.2)
$ git checkout test
M jingwei-server/src/main/java/com/taobao/jingwei/server/service/cmd/GetCustomerTarCmd.java
M jingwei-server/src/main/java/com/taobao/jingwei/server/util/ServerUtil.java
Switched to branch 'test'
shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (test)
$ git branch
br-2.1.2.2
master
* test
M 表示从原来分支(上一次修改没有提交br-2.1.2.2)带过来的修改
删除本地分支 git branch -d xxxxx
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
$ git branch
* master
test
$ git branch -d test
Deleted branch test (was f8aed16).
$ git branch
* master
删除远程版本
$ git push origin :test
删除远程分支
git branch -r -d origin/branch-name
git push origin :branch-name
一不小心把本地的临时分支push到server上去了,想要删除。
一开始用git branch -r -d origin/branch-name
不成功,发现只是删除的本地对该远程分支的track。
正确的方法应该是这样:git push origin :branch-name
冒号前面的空格不能少,原理是把一个空分支push到server上,相当于删除该分支。
放弃本地修改,强制更新
$ git fetch --all
Fetching origin
$ git reset --hard origin/master
HEAD is now at cdb1a85 xxxxxxxxxxxxxx
git fetch 只是下载远程的库的内容,不做任何的合并
git reset 把HEAD指向刚刚下载的最新的版本