参考:
常用命令
abandon Permanently abandon a development branch
branch View current topic branches
branches View current topic branches
checkout Checkout a branch for development
cherry-pick Cherry-pick a change.
diff Show changes between commit and working tree
diffmanifests Manifest diff utility
download Download and checkout a change
grep Print lines matching a pattern
info Get info on the manifest branch, current branch or unmerged branches
init Initialize repo in the current directory
list List projects and their associated directories
overview Display overview of unmerged project branches
prune Prune (delete) already merged topics
rebase Rebase local branches on upstream branch
smartsync Update working tree to the latest known good revision
stage Stage file(s) for commit
start Start a new branch for development
status Show the working tree status
sync Update working tree to the latest revision
upload Upload changes for code review
常用链接
# 环境变量
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
export REPO_URL='https://gerrit-googlesource.proxy.ustclug.org/git-repo'
# .repo/manifests.git/config
url = git://mirrors.ustc.edu.cn/aosp/platform/manifest
# .repo/manifest.xml
fetch="https://aosp.tuna.tsinghua.edu.cn"
单个仓库链接拼装
比如: manifest里project路径是platform/prebuilts/ninja/windows-x86,则git链接是 https://aosp.tuna.tsinghua.edu.cn/platform/prebuilts/ninja/windows-x86
替换已有的 AOSP 源代码的 remote(以后从该remote同步代码)
打包下载的aosp源码里的manifest内容是:
<remote name="aosp"
fetch=".."
review="https://android-review.googlesource.com/" />
<default revision="master"
remote="aosp"
sync-j="4" />
将 .repo/manifest.xml 这个 remote 的 fetch 链接改掉,diff如下:
<manifest>
<remote name="aosp"
- fetch="https://android.googlesource.com"
+ fetch="https://aosp.tuna.tsinghua.edu.cn"
review="android-review.googlesource.com" />
<remote name="github"
初使化仓库并指定分支
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b emu-2.5-release
与线上aosp同步
repo sync
如果当前目录只有.repo,则sync后目录下会出现很多代码文件夹。如:art、build、dalvik、developers、device、frameworks、hardware等
同步时丢弃修改的代码
如果本地版本库中的源代码有一些改动,执行上述命令后,会出现如下提示
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
仅从本地checkout出来代码,不从远程fetch
repo sync --local-only
分支管理
查看所有分支
cd .repo/manifest
git branch -a
# 或
git branch -a | cut -d / -f 3
切换分支
$ repo init -b android-4.2.2_r1
repo切换分支后,cat .repo/manifests.git/config
可见以下内容,在branch "default"
的merge
那里,没切换前是merge = refs/heads/master
,切换后如下:
[core]
repositoryformatversion = 0
filemode = false
[filter "lfs"]
smudge = git-lfs smudge --skip -- %f
[remote "origin"]
url = git://mirrors.ustc.edu.cn/aosp/platform/manifest
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "default"]
remote = origin
merge = refs/heads/android-4.2.2_r1
# 创建自己的新分支
$ repo start gingerbread-release --all
# 查看当前的分支
$ repo branches
切换代码分支
repo checkout emu-2.6-release
repo branches //查看分支
repo status //查看文件状态
Trace
需要在shell里设置export REPO_TRACE=1
,然后就能看到过程中使用的git指令。
网友评论