repo工具是如何简化我们使用git的?

《repo与git的关系》让我们知道如何在linux配置repo。repo是一个python写的脚本,脚本里依然用git命令来管理仓库,git命令是很多的,功能很强大。往往,功能越强大,就意味着越灵活,也就意味着学习它是需要花较多时间和精力的。另外一个事实是,每个开发都不会用完git所有的功能。所以为了简化git的使用,repo就出现了,我们来看看repo封装了git后,向我们了哪些功能。

  1. help:获得repo的帮助文档

查看帮助文档:

repo help

查看repo命令的帮助信息,如查看init命令的帮助信息

repo help init
  1. init
    在当前目录初始repo,它会创建一个.repo隐藏目录,这个隐藏目录包含了repo源代码和标准的android manifest 文件等的git仓库信息。
//-u:用于指定获取manifest仓库(清单仓库)的URL
repo init -u url [options ]

如获取openharmony OS的manifest仓库

repo init -u https://gitee.com/openharmony/manifest.git

指定要获取的分支

-b master --no-repo-verify

// -b master:获取master分支
repo init -u https://gitee.com/openharmony/manifest.git -b master

在仓库中选择一个manifest文件

// -m:指定要获取的文件
repo init -u https://gitee.com/openharmony/manifest.git -m oy-plus.xml

在init执行完成后,我们在~/HmOS的目录下有了一个隐藏目录.repo。那么接下来所有repo的命令的工作目录必须是.repo的父目录,如这里的~/HmOS或者~/HmOS的子目录,总的来说,都必须在~/HmOS这个目录里。

  1. sync
repo sync [project-list]

把远程仓库上的改变和更新都同步到本地环境,确保在开发前,本地仓库与远程仓库的一致性。减少以后合并代码的冲突或其他方面的问题。

这个命令后面有一个项目列表,意味着使用repo的项目往往比较大,依赖的项目也比较多,通过项目列表可以单独去更新某个项目的文件,如果次次都要更新全部项目,那会很耗时,现在可以指定更新会比较高效。如一个手机操作系统可能依赖camera project,network project,framwork project等等。如果不指定就是同步所有。

当我们执行repo sync这个命令时,如果项目从来没有与远程仓库同步过,那么这时操作就是git clone的行为,把远程仓库clone到本地,所有的分支都会被复制到本地来。如果项目曾经同步远程仓库,那么这时的作操就是git remote updategit rebase origin/branch这里的branch指是当前check out的分支名。如果本地当前的分支在远程并没有对应的分支,那么就什么都不操作。这里有个地方要提一下,如果repo sync操作出现了合并冲突(一般底层就是执行了git rebase操作),那么我们就要用git命令去处理这些冲突,如git rebase --continue(我不推这个,还是乖乖地处理好冲突再同步多一次。repo sync也会同步更新.repo文件夹里的文件。

  1. upload
repo upload [project-list ]

如果没有指定项目列表,就是上传所有的改动。如果有指定项目,那么repo会对比本地分支与远程分支,然后提醒你在还没有上传的分支中选择一个或多个来上传。当我们选择好要上传的分支后,我们在这些分支所做改动就会通过SSH连接传输到Gerrit。SSH是需要配置的。当Gerrit通过SSH服务器收到数据后,它将把每个提交转换为一个更改,以便审阅者可以单独对每个提交进行评论。就像在Github上那样去可以审查提交上来的代码,留评论。

  1. diff

显示提交和工作树之间的更改。

repo diff [project-list]
  1. download
    将指定的更改下载到指定的本地目录。
repo download target change

For example, to download change 1241 into your :

//下载改动1241到本地目录platform/frameworks/base directory
$ repo download platform/frameworks/base 1241
  1. forall
    执行shell命令
repo forall [project-list ] -c command [arg. ..]
  1. start
    创建一个新的分支
repo start newbranchname [project-list ]
  1. status
    显示当前工作目录或指定项目的状态
repo status [project-list ]

状态的信息:
A : 新增
M:修改
R: 重新命名
C:该文件是从另一个文件复制过来的。
T:文件模式被修改了
U:文件出现了冲突,未合并
- :文件状态未被修改。当你修改了,但未提交,就是这个状态。

从上面的命令使用,我们会发现repo在多项目开发中特别有用,尤其是那些有项目列表指定的命令。

To make edits to changes after they have been uploaded, you should use a tool like git rebase -i or git commit --amend to update your local commits. After your edits are complete: Make sure the updated branch is the currently checked out branch. For each commit in the series, enter the Gerrit change ID inside the brackets: # Replacing from branch foo [ 3021 ] 35f2596c Refactor part of GetUploadableBranches to lookup one specific... [ 2829 ] ec18b4ba Update proto client to support patch set replacments # Insert change numbers in the brackets to add a new patch set. # To create a new change record, leave the brackets empty. After the upload is complete the changes will have an additional Patch Set. If you only want to upload the currently checked out Git branch, you can use the flag --current-branch (or --cbr for short). diff repo diff [<PROJECT_LIST>] Shows outstanding changes between commit and working tree using git diff. download repo download <TARGET> <CHANGE> Downloads the specified change from the review system and makes it available in your project's local working directory. For example, to download change 23823 into your platform/build directory: repo download platform/build 23823 A repo sync should effectively remove any commits retrieved via repo download. Or, you can check out the remote branch; e.g., git checkout m/master. Note: There is a slight mirroring lag between when a change is visible on the web in Gerrit and when repo download will be able to find it for all users, because of replication delays to all servers worldwide. forall repo forall [<PROJECT_LIST>] -c <COMMAND> Executes the given shell command in each project. The following additional environment variables are made available by repo forall: REPO_PROJECT is set to the unique name of the project. REPO_PATH is the path relative to the root of the client. REPO_REMOTE is the name of the remote system from the manifest. REPO_LREV is the name of the revision from the manifest, translated to a local tracking branch. Used if you need to pass the manifest revision to a locally executed git command. REPO_RREV is the name of the revision from the manifest, exactly as written in the manifest. Options: -c: command and arguments to execute. The command is evaluated through /bin/sh and any arguments after it are passed through as shell positional parameters. -p: show project headers before output of the specified command. This is achieved by binding pipes to the command's stdin, stdout, and sterr streams, and piping all output into a continuous stream that is displayed in a single pager session. -v: show messages the command writes to stderr. prune repo prune [<PROJECT_LIST>] Prunes (deletes) topics that are already merged. start repo start <BRANCH_NAME> [<PROJECT_LIST>] Begins a new branch for development, starting from the revision specified in the manifest. The <BRANCH_NAME> argument should provide a short description of the change you are trying to make to the projects.If you don't know, consider using the name default. The <PROJECT_LIST> specifies which projects will participate in this topic branch. Note: "." is a useful shorthand for the project in the current working directory. status repo status [<PROJECT_LIST>] Compares the working tree to the staging area (index) and the most recent commit on this branch (HEAD) in each project specified. Displays a summary line for each file where there is a difference between these three states. To see the status for only the current branch, run repo status. The status information will be listed by project. For each file in the project, a two-letter code is used: In the first column, an uppercase letter indicates how the staging area differs from the last committed state. letter meaning description - 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 In the second column, a lowercase letter indicates how the working directory differs from the index. 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 Was this page helpful? Let us know how we did:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值