人丑就要多读书,多喝水!
先介绍一些命令:
创建新的 git 仓库 : git init
拉服务器代码 : git clone username@host:/path/to/repository
创建新分支:git branch branchName
切换到分支:git checkout branchName
创建并切换 : git checkout -b branchName
删除分支 : git branch -d branchName
切回主分支 : git checkout master
查看分支 : git branch -av
提交的文件 : git add <filename> 、 git add *
添加提交信息 : git commit -m "代码提交信息"
查看origin : git remote -v
将代码push到远程仓库 : git push <origin> HEAD:refs/for/<BRANCH>
查看git提交 : git log
更新本地仓库 : git pull
提交过程:
提交代码的过程就是将你本地仓库修改的代码(文件)提交到远程仓库中的过程。
一般通过从网上拉下来的代码,我们不会在任何一个分支上,可以用
git branch -av
查看自己处在的分支和所有的分支。不处于任何分支上好像也是可以提交代码的。具体过程为:
1、查看自己修改的文件:
git diff
在这里也可以新建一个本地仓库的分支:
例如:
git checkout -b newbranchName
2、添加到缓存区
git add <file>
3、添加提交信息
git commit -m "提交信息"
4、查看origin
git remote -v
例如:
git remote -v
origin ssh:xxxxxxxxxxxxxxxxxxx (fetch)
origin ssh:xxxxxxxxxxxxxxx (push) /*一会要用到 */
5、查看主分支名称
git branch -av
例如:
* hao xxxxxxxxxxxxxxxxxxxxxx
remotes/m/qqqq -> origin/qqqq /*主分支名称为qqqq*/
remotes/origin/qqqq
一会要用到主分支名称。
6、将文件提交到远程仓库
git push [origin] HEAD:refs/for/[主分支名称]
例如:
git push ssh:xxxxxxxxxxxxxxxxxxx HEAD:refs/for/qqqq
7、指定Reviewers
到gerrit网站上找到自己的提交,点击进去,在Reviewers处可以添加,不添加可以自己给+2权限入库。