$ repo usage: repo COMMAND [ARGS] The most commonly used repo commands are: 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 See 'repo help <command>' for more information on a specific command. See 'repo help --all' for a complete list of recognized commands.
$ repo error: repo is not installed. Use "repo init" to install it here. 随便一个目录执行repo命令是会保持的,然后会提示你先 repo init 安装,这个安装就是会安装到当前目录,在当前目录下面的.repo 目录。一个隐藏目录。
Options: -h, --help show this help message and exit
Logging options: -q, --quiet be quiet
Manifest options: -u URL, --manifest-url=URL manifest repository location -b REVISION, --manifest-branch=REVISION manifest branch or revision -m NAME.xml, --manifest-name=NAME.xml initial manifest file --mirror create a replica of the remote repositories rather than a client working directory --reference=DIR location of mirror directory --depth=DEPTH create a shallow clone with given depth; see git clone --archive checkout an archive instead of a git repository for each project. See git archive. -g GROUP, --groups=GROUP restrict manifest projects to ones with specified group(s) [default|all|G1,G2,G3|G4,-G5,-G6] -p PLATFORM, --platform=PLATFORM restrict manifest projects to ones with a specified platform group [auto|all|none|linux|darwin|...] --no-clone-bundle disable use of /clone.bundle on HTTP/HTTPS
repo Version options: --repo-url=URL repo repository location --repo-branch=REVISION repo branch or revision --no-repo-verify do not verify repo source code
Other options: --config-name Always prompt for name/e-mail
fatal: --mirror is only supported when initializing a new workspace. Either delete the .repo folder in this workspace, or initialize in another location.
Options: -h, --help show this help message and exit -f, --force-broken continue sync even if a project fails to sync --force-sync overwrite an existing git directory if it needs to point to a different object directory. WARNING: this may cause loss of data -l, --local-only only update working tree, don't fetch -n, --network-only fetch only, don't update working tree -d, --detach detach projects back to manifest revision -c, --current-branch fetch only current branch from server -q, --quiet be more quiet -j JOBS, --jobs=JOBS projects to fetch simultaneously (default 4) -m NAME.xml, --manifest-name=NAME.xml temporary manifest to use for this sync --no-clone-bundle disable use of /clone.bundle on HTTP/HTTPS -u MANIFEST_SERVER_USERNAME, --manifest-server-username=MANIFEST_SERVER_USERNAME username to authenticate with the manifest server -p MANIFEST_SERVER_PASSWORD, --manifest-server-password=MANIFEST_SERVER_PASSWORD password to authenticate with the manifest server --fetch-submodules fetch submodules from server --no-tags don't fetch tags --optimized-fetch only fetch projects fixed to sha1 if revision does not exist locally --prune delete refs that no longer exist on the remote -s, --smart-sync smart sync using manifest from the latest known good build -t SMART_TAG, --smart-tag=SMART_TAG smart sync using manifest from a known tag
repo Version options: --no-repo-verify do not verify repo source code
-d选项,detach是分离,剥离的意思,一般在git中用git status查看有时候能看到。 HEAD detached at 6beb886d10ec,这个是啥意思呢?这个指头指针剥离自一个revision, 也就是当前分支剥离自一个revision,也就是一个没用名字的分支,也就是当前分支是一个匿名分支。 这个选项在repo sync时候能有什么作用呢?我们接下来详细介绍。
$ git br -vv * (no branch) 48b4a9a Merge 6f578b199a8bbd8b9c053526a459db0600bf640c on remote branch
然后执行 repo sync .,发现又回到之前的那个提交了
1 2
* (HEAD detached at 5e51f0b) 5e51f0b Merge 6a461864882ef2fec0caab813044b2106bfa199d on remote branch
情况1
结论:
不带-d选项,在命名分支上,不是追踪远程的分支。sync后会剥离匿名分支上。
再做个实验,我们用之前的一个提交6b66e01 创建一个新分支test然后切换到test分支上。
1 2 3 4 5 6 7 8 9 10 11
$ git co 6b66e01 -b test Previous HEAD position was 5e51f0b... Merge 6a461864882ef2fec0caab813044b2106bfa199d on remote branch Switched to a new branch 'test'
$ git st On branch test nothing to commit, working tree clean
$ git br -vvv * test 6b66e01 msm8996: Added Sustained and VR perf mode powerhints in xml $
device/qcom/msm8996/: leaving test; does not track upstream
$ git br -vvv * (HEAD detached at 5e51f0b) 5e51f0b Merge 6a461864882ef2fec0caab813044b2106bfa199d on remote branch test 6b66e01 msm8996: Added Sustained and VR perf mode powerhints in xml
$ repo sync . Fetching project platform/vendor/qcom/thulium error: Your local changes to the following files would be overwritten by checkout: AndroidBoard.mk Please commit your changes or stash them before you switch branches. Aborting
device/qcom/msm8996/: leaving test; does not track upstream error: device/qcom/msm8996/: platform/vendor/qcom/thulium checkout 5e51f0bbfc618dcc9518be616a2843f9c69dbfdf
$ git st On branch test Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)
modified: AndroidBoard.mk
no changes added to commit (use "git add" and/or "git commit -a") $
$ git br -vvv * dev 5e51f0b [shgit/qcom_o_dev_20171101] Merge 6a461864882ef2fec0caab813044b2106bfa199d on remote branch 这个本地dev分支,追踪对应的远端分支 test fe80d2f test 这个是本地test分支 $
device/qcom/msm8996/: manifest switched refs/heads/sdm660_o_bringup_20170719...qcom_o_dev_20171101 device/qcom/msm8996/: discarding 1 commits removed from upstream project device/qcom/msm8996/ First, rewinding head to replay your work on top of it...
$ git br -vvvv dev 5e51f0b [shgit/qcom_o_dev_20171101] Merge 6a461864882ef2fec0caab813044b2106bfa199d on remote branch * sdm660_o_bringup_20170719 5e51f0b [shgit/qcom_o_dev_20171101] Merge 6a461864882ef2fec0caab813044b2106bfa199d on remote branch qcom_msm8953_apk_20170703 880dcbf [shgit/qcom_msm8953_apk_20170703] Merge e3ce047a16037379bfd859e14666a6c7eb2eae05 on remote branch $
–force-sync 强制sync的意思,也就是当git仓库地址遍历会报个错误,错误中会提示你使用–force-sync,这个时候你就加上这个选项重新同步代码。 overwrite an existing git directory if it needs to point to a different object directory. WARNING: this may cause loss of data 类似的会报出如下错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
error: Cannot fetch platform/vendor/qcom/proprietary (GitError: --force-sync not enabled; cannot overwrite a local work tree. If you're comfortable with the possibility of losing the work tree's git metadata, use `repo sync --force-sync vendor/qcom/proprietary` to proceed.) Exception in thread Thread-85: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 763, in run self.__target(*self.__args, **self.__kwargs) File ".repo/repo/subcmds/sync.py", line 270, in _FetchProjectList success = self._FetchHelper(opt, project, *args, **kwargs) File ".repo/repo/subcmds/sync.py", line 314, in _FetchHelper prune=opt.prune) File ".repo/repo/project.py", line 1148, in Sync_NetworkHalf self._InitGitDir(force_sync=force_sync) File ".repo/repo/project.py", line 2177, in _InitGitDir raise e GitError: --force-sync not enabled; cannot overwrite a local work tree. If you're comfortable with the possibility of losing the work tree's git metadata, use `repo sync --force-sync vendor/qcom/proprietary` to proceed.
-l, –local-only 只更新本地工作空间,不去远端服务器拉取代码。什么意思呢?repo sync在同步代码的时候是先把服务器上的代码更新(拉取,fetch)到.repo目录下面的,然后进行checkout操作。这里的–local-only就是只进行checkout操作,也就是把.repo 目录下面的代码更新到工作空间目录中。 only update working tree, don’t fetch
-n, –network-only 只更新,值拉取服务器代码到.repo 目录下。这个就是和上面的–local-only相对应的。 fetch only, don’t update working tree。