Version Control with Repo and Git
2011-04-27 15:29
232 查看
To work with the Android code, you will need to use both Git and Repo. In most situations, you can use Git instead of Repo, or mix Repo and Git commands to form complex commands. Using Repo for basic across-network operations will make your work much simpler, however.
Git is an open-source version-control system designed to handle very large projects that are distributed over multiple repositories. In the context of Android, we use Git for local operations such as local branching, commits, diffs, and edits. One of the challenges in setting up the Android project was figuring out how to best support the outside community--from the hobbiest community to large OEMs building mass-market consumer devices. We wanted components to be replaceable, and we wanted interesting components to be able to grow a life of their own outside of Android. We first chose a distributed revision control system, then further narrowed it down to Git.
Repo is a repository management tool that we built on top of Git. Repo unifies the many Git repositories when necessary, does the uploads to our revision control system, and automates parts of the Android development workflow. Repo is not meant to replace Git, only to make it easier to work with Git in the context of Android. The repo command is an executable Python script that you can put anywhere in your path. In working with the Android source files, you will use Repo for across-network operations. For example, with a single Repo command you can download files from multiple repositories into your local working directory.
Gerrit is a web-based code review system for projects that use git. Gerrit encourages more centralized use of Git by allowing all authorized users to submit changes, which are automatically merged if they pass code review. In addition, Gerrit makes reviewing easier by displaying changes side by side in-browser and enabling inline comments.
The basic pattern of interacting with the repositories is as follows:
Use
Edit the files.
Use
Use
Use
To synchronize the files for selected projects:
To start a topic branch using Repo:
To verify that your new branch was created:
To switch to another branch that you have created in your local work environment:
To see a list of existing branches:
or
The name of the current branch will be preceded by an asterisk.
Note: A bug might be causing
You can stage your changes by running
which accepts as arguments any files or directories within the project directory. Despite the name,
To see uncommitted edits:
The
You will be prompted for a commit message in your favorite editor; please provide a helpful message for any changes you submit to the AOSP. If you do not add a log message, the commit will be aborted.
Next run
This will list the changes you have committed and prompt you to select which branches to upload to the review server. If there is only one branch, you will see a simple
View the files that are unmerged (status code = U).
Edit the conflict regions as necessary.
Change into the relevant project directory, run
When the rebase is complete start the entire sync again:
To safely remove stale topic branches:
Deleting a client will permanently delete any changes you have not yet uploaded for review.
Git is an open-source version-control system designed to handle very large projects that are distributed over multiple repositories. In the context of Android, we use Git for local operations such as local branching, commits, diffs, and edits. One of the challenges in setting up the Android project was figuring out how to best support the outside community--from the hobbiest community to large OEMs building mass-market consumer devices. We wanted components to be replaceable, and we wanted interesting components to be able to grow a life of their own outside of Android. We first chose a distributed revision control system, then further narrowed it down to Git.
Repo is a repository management tool that we built on top of Git. Repo unifies the many Git repositories when necessary, does the uploads to our revision control system, and automates parts of the Android development workflow. Repo is not meant to replace Git, only to make it easier to work with Git in the context of Android. The repo command is an executable Python script that you can put anywhere in your path. In working with the Android source files, you will use Repo for across-network operations. For example, with a single Repo command you can download files from multiple repositories into your local working directory.
Gerrit is a web-based code review system for projects that use git. Gerrit encourages more centralized use of Git by allowing all authorized users to submit changes, which are automatically merged if they pass code review. In addition, Gerrit makes reviewing easier by displaying changes side by side in-browser and enabling inline comments.
Basic Workflow
The basic pattern of interacting with the repositories is as follows:
Use
repo startto start a new topic branch.
Edit the files.
Use
git addto stage changes.
Use
git committo commit changes.
Use
repo uploadto upload changes to the review server.
Task reference
The task list below shows a summary of how to do common Repo and Git tasks. For complete quick-start information and examples, see Getting started.Synchronizing your client
To synchronize the files for all available projects:$ repo sync
To synchronize the files for selected projects:
$ repo sync PROJECT0 PROJECT1 PROJECT2 ...
Creating topic branches
Start a topic branch in your local work environment whenever you begin a change, for example when you begin work on a bug or new feature. A topic branch is not a copy of the original files; it is a pointer to a particular commit. This makes creating local branches and switching among them a light-weight operation. By using branches, you can isolate one aspect of your work from the others. For an interesting article about using topic branches, see Separating topic branches.To start a topic branch using Repo:
$ repo start BRANCH_NAME
To verify that your new branch was created:
$ repo status
Using topic branches
To assign the branch to a particular project:$ repo start BRANCH_NAME PROJECT
To switch to another branch that you have created in your local work environment:
$ git checkout BRANCH_NAME
To see a list of existing branches:
$ git branch
or
$ repo branches
The name of the current branch will be preceded by an asterisk.
Note: A bug might be causing
repo syncto reset the local topic branch. If
git branchshows * (no branch) after you run
repo sync, then run
git checkoutagain.
Staging files
By default, Git notices but does not track the changes you make in a project. In order to tell git to preserve your changes, you must mark them for inclusion in a commit. This is also called "staging".You can stage your changes by running
git add
which accepts as arguments any files or directories within the project directory. Despite the name,
git adddoes not simply add files to the git repository; it can also be used to stage file modifications and deletions.
Viewing client status
To list the state of your files:$ repo status
To see uncommitted edits:
$ repo diff
The
repo diffcommand shows every local edit that you have made that would not go into the commit, if you were to commit right now. To see every edit that would go into the commit if you were to commit right now, you need a Git command,
git diff. Before running it, be sure you are in the project directory:
$ cd ~/WORKING_DIRECTORY/PROJECT $ git diff --cached
Committing changes
A commit is the basic unit of revision control in git, consisting of a snapshot of directory structure and file contents for the entire project. Creating a commit in git is as simple as typinggit commit
You will be prompted for a commit message in your favorite editor; please provide a helpful message for any changes you submit to the AOSP. If you do not add a log message, the commit will be aborted.
Uploading changes to Gerrit
Before uploading, update to the latest revisions:repo sync
Next run
repo upload
This will list the changes you have committed and prompt you to select which branches to upload to the review server. If there is only one branch, you will see a simple
y/nprompt.
Recovering sync conflicts
If arepo syncshows sync conflicts:
View the files that are unmerged (status code = U).
Edit the conflict regions as necessary.
Change into the relevant project directory, run
git addand
git commitfor the files in question, and then "rebase" the changes. For example:
$ git add .
$ git commit$ git rebase --continue
When the rebase is complete start the entire sync again:
$ repo sync PROJECT0 PROJECT1 ... PROJECTN
Cleaning up your client files
To update your local working directory after changes are merged in Gerrit:$ repo sync
To safely remove stale topic branches:
$ repo prune
Deleting a client
Because all state information is stored in your client, you only need to delete the directory from your filesystem:$ rm -rf WORKING_DIRECTORY
Deleting a client will permanently delete any changes you have not yet uploaded for review.
Git and Repo cheatsheet
相关文章推荐
- Advanced SQL Server Monitor with Performance Graph, Analysis and Version Control
- 优达学城《Version control with Git》笔记
- 读书笔记:《Version Control With Git》
- Learning Source Control with Git and SourceTree.pdf
- 【引】Version Control System - SVN - Developing and Deploying with Branches
- repo init 报:ValueError: invalid literal for int() with base 10: '8 (Apple Git-58)'
- svn:is not under version control and is not part of the commit, yet its child解决办法
- Visual Studio 2013 always switches source control plugin to Git and disconnect TFS
- Navicat连接oracle,出现Only compatible with oci version 8.1 and&nb (转)
- ui page control and scrollview with indicator at bottom
- print control with css and javascript
- Jenkins 安装启动提示“iJob for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.”
- Patch workflow with mutt and git
- 项目管理实践【五】自动编译和发布网站【Using Visual Studio with Source Control System to build and publish website automatically】
- 项目管理实践【四】自动编译和发布网站【Using Visual Studio with Source Control System to build and publish website automatically】
- Visual Studio 2013 always switches source control plugin to Git and disconnect TFS
- FW-binary - tree - with id and sibling connected - java version 2013年12月18日1:21
- BlueROV-11: Full Flight Control and Mission Planning with QGroundControl
- Control two computers with one mouse and keyboard
- Git使用笔记(四)Using Repo and Git