【转】Repo切换分支与同步代码
1, 查看可切换的分支
在AOSP目录下
cd .repo/manifests
git branch -a | cut -d / -f 3
2,切换分支(以android-7.0.0_r1为例)
repo init -u https://android.googlesource.com/platform/manifest -b android-7.0.0_r1
3,同步代码
repo sync
如果本地版本库中的源代码有一些改动,执行上述命令后,会出现如下提示(笔者本地为例):
build/: discarding 1 commits
dalvik/: discarding 2 commits
kernel/: discarding 6 commits
packages/apps/Calendar/: discarding 1 commits
packages/apps/Contacts/: discarding 2 commits
packages/apps/Mms/: discarding 1 commits
packages/apps/Music/: discarding 1 commits
packages/apps/Phone/: discarding 1 commits
vendor/embinux/support-tools/: discarding 1 commits
这时需要使用下面的操作命令:
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
Git与Repo入门
REPO
repo start <topic_name>
开启一个新的主题,其实就是每个Project都新建一个分支。
repo init -u <url> [OPTIONS]
在当前目录下初始化repo,会在当前目录生生成一个.repo目录,像Git Project下的.git一样,-u指定url,可以加参数-m指定manifest文件,默认是default.xml,.repo/manifests保存manifest文件。.repo/projects下有所有的project的数据信息,repo是一系列git project的集合,每个git project下的.git目录中的refs等目录都是链接到.repo/manifests下的。
repo manifest
可以根据当前各Project的版本信息生成一个manifest文件
repo sync [PROJECT1...PROJECTN]
同步Code。
repo status
查看本地所有Project的修改,在每个修改的文件前有两个字符,第一个字符表示暂存区的状态。
| - | no change | same in HEAD and index |
| A | added | not in HEAD, in index |
| M | modified | in HEAD, modified in index |
| D | deleted | in HEAD, not in index |
| R | renamed | not in HEAD, path changed in index |
| C | copied | not in HEAD, copied from another in index |
| T | mode changed | same content in HEAD and index, mode changed |
| U | unmerged | conflict between HEAD and index; resolution required |
每二个字符表示工作区的状态
letter | meaning | description |
---|---|---|
- | new/unknown | not in index, in work tree |
m | modified | in index, in work tree, modified |
d | deleted | in index, not in work tree |
repo prune <topic>
删除已经merge的分支
repo abandon <topic>
删除分支,无论是否merged
repo branch或repo branches
查看所有分支
repo diff
查看修改
repo upload
上传本地提交至服务器
repo forall [PROJECT_LIST]-c COMMAND
对指定的Project列表或所有Project执行命令COMMAND,加上-p参数可打印出Project的路径。
repo forall -c 'git reset --hard HEAD;git clean -df;git rebase --abort'
这个命令可以撤销整个工程的本地修改。
说明:文中关于Git的知识大多来自Pro-GIt,这本书感觉不错,想学习的可以找来看:Pro-Git