repo start 和仓库分支名称

20130111
关于repo和git


4.1 项目
repo init -u [email protected]:android/platform/manifest.git -b XXXXroid4.1 [email protected]:tools/repo.git
上面这个命令在repo init 的时候选择了manifest.xml的分支为XXXXroid4.1。但这并不能保证在你repo sync 过后,接下来可以将所有的仓库全部切换到XXXXroid4.1分支。因为并不是每个仓库都有这个分支!!!!
前面我犯了一个错误,认为所有的仓库都有同样个数的对应名字的分支!所以我每次在repo sync完成后总是喜欢用
git checkout --track remotes/korg/XXXXroid4.1 -b XXXXroid4.1 
来基于manifest.xml文件遍历所有的仓库,将分支切换到同一个。以前一直都可以。但是今天却出了问题。原因就是有的仓库在远程根本就没有你要的分支。也就是:不是每个仓库都需要切换到同样的分支名。
对于一个工程而言,repo允许它的每个仓库所跟踪的远程仓库的分支名不完全统一!至于一个仓库到底在一个工程中使用那个对应的分支,在manifest.xml中会去指定!
看一个manifest.xml的例子:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>


  <remote  name="korg"
           fetch="[email protected]:android/"
           review="review.source.xxxxxxxxxx.com/gerrit/" />
  <default revision="XXXXroid4.1"    这里指定默认的分支名
           remote="korg"
           sync-j="4" />


  <project path="build" name="platform/build" >  
    <copyfile src="core/root.mk" dest="Makefile" />
  </project>
  <project path="abi/cpp" name="platform/abi/cpp" />
  <project path="bionic" name="platform/bionic" />
  <project path="bootable/bootloader/legacy" name="platform/bootable/bootloader/legacy" />
  <project path="bootable/diskinstaller" name="platform/bootable/diskinstaller" />
  <project path="bootable/recovery" name="platform/bootable/recovery" />
  <project path="cts" name="platform/cts" />


以上几个工程都是一致的:path指定本地仓库位置,name指定远程的仓库位置,本地仓库将默认跟踪远程的XXXXroid4.1分支。
再来看几个:(和上面的出自同一个manifest.xml中)
  <project path="packages/apps/10086cn" name="platform/packages/apps/10086cn" revision="XXXXroid_own_copyright" />
  <project path="packages/apps/AppBackup" name="platform/packages/apps/AppBackup" revision="XXXXroid_own_copyright" />
  <project path="packages/apps/AudioProfile" name="platform/packages/apps/AudioProfile" revision="XXXXroid_own_copyright" />
  <project path="packages/apps/Monternet" name="platform/packages/apps/Monternet" revision="XXXXroid_own_copyright" />
  <project path="packages/apps/MyFavorites" name="platform/packages/apps/MyFavorites" revision="XXXXroid_own_copyright" />
  <project path="packages/apps/XXXXNote" name="platform/packages/apps/XXXXNote" revision="XXXXroid_own_copyright" />
  <project path="packages/apps/ValidationTools" name="platform/packages/apps/ValidationTools" revision="XXXXroid_own_copyright" />


这几个工程除了指定name 和path外,还指定了revision。这个revision就是这些仓库在sync完成后的默认状态,即,跟踪的是远程仓库的XXXXroid_own_copyright分支。不指定就用最前面说的default分支名:XXXXroid4.1    指定了就用指定的。


repo init -b XXXXroid4.1  将manifest切换到你要的分支
repo sync -j4 -q  同步代码

repo start local-0113 --all  基于manifest.xml创建分支



接下来用repo start来在每个仓库建立分支,并保证每个分支跟到远程的对应分支上,不要像我前面的用repo forall 来折腾了。我已经验证了,repo start真的可以根据manifest.xml中的信息来让本地分支跟到不同的远程分支!下面是我的验证。


apuser@YaochuanLiubt:~/mywork/403-akm$ repo start local-0113 --all
Starting local-0113: 100% (248/248), done.  
apuser@YaochuanLiubt:~/mywork/403-akm$ cd kernel/
apuser@YaochuanLiubt:~/mywork/403-akm/kernel$ git branch
* local-0113
apuser@YaochuanLiubt:~/mywork/403-akm/kernel$ cat .git/config 
[core]
repositoryformatversion = 0
filemode = true
[remote "korg"]
url = [email protected]:android/kernel/common.git
review = review.source.xxxxxxxxxx.com/gerrit/
projectname = kernel/common
fetch = +refs/heads/*:refs/remotes/korg/*
[branch "local-0113"]
remote = korg
merge = XXXXroid4.0.3_vlx_3.0 /看,这里跟的是这个/




apuser@YaochuanLiubt:~/mywork/403-akm$ cd packages/apps/10086cn/
apuser@YaochuanLiubt:~/mywork/403-akm/packages/apps/10086cn$ git branch
* local-0113
apuser@YaochuanLiubt:~/mywork/403-akm/packages/apps/10086cn$ cat .git/config 
[core]
repositoryformatversion = 0
filemode = true
[remote "korg"]
url = [email protected]:android/platform/packages/apps/10086cn.git
review = review.source.xxxxxxxxxx.com/gerrit/
projectname = platform/packages/apps/10086cn
fetch = +refs/heads/*:refs/remotes/korg/*
[branch "local-0113"]
remote = korg
merge = XXXXroid_own_copyright /看,这里跟的是另一个!/
apuser@YaochuanLiubt:~/mywork/403-akm/packages/apps/10086cn$ 
apuser@YaochuanLiubt:~/mywork/403-akm/packages/apps/10086cn$

所以,以后就不要在用repo forall 这种方式来建立分支了! 


另外,在用git checkout --track remotes/korg/XXXXroid4.1 -b XXXXroid4.1 创建一个本地分支的时候,会指定其跟踪的远程分支,如果你在本地commit新的change后,执行git status时会显示你的本地分支和你所跟踪的远程分支在commit个数上的异同,但是如果用repo start搞的本地分支的话,虽然也是跟踪到了一个具体的远程分支,但是当我用git status的时候却不显示本地和远程的异同,这个不爽的很。因为我总有一种需要就是在工程的根目录执行repo forall -p -c git status来遍历整个工程的所有仓库,来找到我在那个本地仓库有提交。毕竟我针对一个问题的修改可能会涉及多个仓库。如果我不这么检查的话,可能在push的时候会忘记某个仓库的修改,从而导致服务器上的代码出现不完整。我是个追求完美的人,你知道。

Topic branches are typically lightweight branches that you create locally and that have a name that is meaningful for you. They are where you might do work for a bug fix or feature (they're also called feature branches) that is expected to take some time to complete.

Another type of branch is the "remote branch" or "remote-tracking branch". This type of branch follows the development of somebody else's work and is stored in your own repository. You periodically update this branch (using git fetch) to track what is happening elsewhere. When you are ready to catch up with everybody else's changes, you would use git pull to both fetch and merge.

I have also seen another kind of branch which is essentially a completely separate tree of files in the same repository. For example, the Git repository itself contains heads named man and html that contain entirely different content from the master branch. I don't know what these types of branches are usually called.


你可能感兴趣的:(repo start 和仓库分支名称)