0


repo使用 git使用

Repo切换分支与同步代码

1,repo forall -c git reset --hard 2,repo init -u https://android.googlesource.com/platform/manifest -b android-7.0.0_r1 3,repo sync

repo使用

下载repo工具

$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo  

or $ wget http://android.git.kernel.org/repo

or $ curl http://android.git.kernel.org/repo >~/bin/repo

$ chmod a+x ~/bin/repo

repo init -u gitserver:manifests.git -m xxx.xml repo项目初始化(xxx.xml文件决定初始化的项目)

repo sync 下载项目代码

repo start xxx --all 创建xxx项目对应的分支或者切换分支(--all意为将所有模块都归为当前xxx分支下)

repo branch 查看当前项目代码所在的分支

repo abandon 分支名 删除不用的本地分支(同git branch -d 分支名)

repo forall -c git checkout -b xxx 项目对应的远程分支名(最好是本地分支和远程分支同名,除主分支外)

repo -c -p git checkout 本地分支 远程分支

repo help command 显示command的详细的帮助信息内容

git使用

git status 显示之前更改的代码文件

git stash 保存更改的代码状态

git stash sava {name} 保存更改的代码状态

git stash list 查看保存记录

git stash apply 还原保存的修改,不从栈中移除

git statsh pop stash@{x} 还原保存的更改,从栈中移除

git stash clear 清除保存的更改记录

git pull --rebase 服务器本地代码同步更新远程库代码

在执行之前需要查看本地代码有没有修改(git status),若有,先保存修改记录(git stash),更新完成后回复更改(git stash applay),如果没有直接执行。(本地有修改记录更新会出错)

git commit 提交修改

git commit -a 一次性提交修改项

git push origin HEAD:refs/for/远程分支名 把代码提交到临时代码库(为gerrit评审)

git add . 一次性提交修改项和添加项

git add 文件 单独提交修改项或添加项

git rm 文件 提交删除文件

git log 查看远程代码提交记录节点信息(q退出)

git reset --soft id 回退到指定提交位置

git reset HEAD^ 撤销最近一次提交,保留修改,只删掉提交记录

git reset --hard HEAD^ 撤销最近一次提交,修改记录也删掉

git reset --soft HEAD^ 代码提交后(git push)需要回退到提交之前的状态

git checkout 文件名 把修改的或删除的文件回退到原状态

git checkout . 回退全部修改

git branch 查看当前代码所在的本地分支(带有*的为当前本地代码分支)

git branch -b 本地分支名称 远程分支名称 将本地代码切换到远程对应的分支

git checkout -b 本地分支名称 远程分支名称 切换到指定的分支

git chencout 本地分支名称 切换到指定分支

git branch -a 查看所有分支

git diff 查看修改的内容

git diff 文件名 查看指定文件 的修改

reference:

http://www.360doc.com/content/14/0220/17/97538_354256755.shtml repo详解

http://blog.csdn.net/stevenhu_223/article/details/8828130 Git和Repo管理使用简要介绍*

http://blog.csdn.net/luoshengyang/article/details/18195205 Android源代码仓库及其管理工具Repo分析

http://blog.csdn.net/wh_19910525/article/details/8164107 repo的小结

Git和Repo的区别

Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项目版本管理。

Repo是谷歌用Python脚本写的调用git的一个脚本。主要是用来下载、管理Android项目的软件仓库(也就是说Repo是用来管理给Git管理的一个个仓库的)

Gerrit简介

基于 Web 的代码评审和项目管理的工具,面向基于 Git 版本控制系统;

为 Git 引入强制性的代码审核机制,非特别的授权设置,向 Git 版本库的推送(Push)必须要经过 Gerrit服务器,经过审核流程后,才能正式纳入代码库;

每一次提交将对应一个评审任务;

通过特殊的分支提交评审任务(refs/for/….);

Gerrit 提供的 Git 服务的端口并非标准的 22 端口,缺省是 29418 端口;

Gerrit缺省的Http端口是8080。

gitk

 输入gitk指令后,会跳出相应的记录信息的窗口,通过该窗口可以查看其它程序员对本项目的远程代码提交记录。

常见问题

   1.缺少changeId无法提交

//如果提交提示:

remote: ERROR: missing Change-Id in commit message footer

remote: Suggestion for commit message:

remote: 20160630-v2

remote:

remote: Change-Id: I00a7de827e1eb4f905693f75dbffdfd7254e064

remote:

remote: Hint: To automatically insert Change-Id, install the hook:

这里报错其实是因为配置的时候没有获取一个“钩子”的东西,因为本地提交到远程版本库的时候中间还要经过一道审核

解决方法:从服务器获取“钩子”到本地,然后再次提交即可:

sudo scp -p -P 29418 xxx@xxx.git.com:hooks/commit-msg .git/hooks/

git commit --amend

2. diff patch

生成标准的patch,只包含diff信息

git diff生成的Patch兼容性强,可以用git apply --check 查看补丁是否能够干净顺利地应用到当前分支中。

例:从master checkout一个新分支修改然后与master对比生成patch。 git diff master > patch

git apply xxx.patch(需要重新commit)

git apply --ignore-whitespace 补丁名:打补丁忽略空格检查。

git撤销打补丁

撤销该补丁的修改效果回到打补丁前代码的状态

命令:patch -R -p1 < my.patch

撤销补丁还有种更方便的方法,将文件还原checkout,但这个是对文件整体的还原,该文件除补丁之外的修改也被还原了。

标签: git github

本文转载自: https://blog.csdn.net/Jun_P/article/details/126550678
版权归原作者 探求之路 所有, 如有侵权,请联系我们删除。

“repo使用 git使用”的评论:

还没有评论