blob: 5a4a2a4b778547776253ee2df3a432a711df7151 [file] [log] [blame] [view]
Skyler Kaufman991ae4d2011-04-07 12:30:41 -07001# Version Control with Repo and Git #
2
3To 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.
4
5**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.
6
7**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](http://review.source.android.com/), 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.
8
9**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.
10
11## Basic Workflow ##
12
13<div style="float:right">
14 <img src="/images/submit-patches-0.png">
15</div>
16
17The basic pattern of interacting with the repositories is as follows:
18
191. Use `repo start` to start a new topic branch.
20
211. Edit the files.
22
231. Use `git add` to stage changes.
24
251. Use `git commit` to commit changes.
26
271. Use `repo upload` to upload changes to the review server.
28
29# Task reference #
30
31The task list below shows a summary of how to do common Repo and Git tasks.
32For complete quick-start information and examples, see [Getting started](downloading.html).
33
34## Synchronizing your client ##
35
36To synchronize the files for all available projects:
37
38 $ repo sync
39
40To synchronize the files for selected projects:
41
42 $ repo sync PROJECT0 PROJECT1 PROJECT2 ...
43
44## Creating topic branches ##
45
46Start 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](http://www.kernel.org/pub/software/scm/git/docs/howto/separating-topic-branches.txt).
47<img src="/images/external-link.png">
48
49To start a topic branch using Repo:
50
51 $ repo start BRANCH_NAME
52
53To verify that your new branch was created:
54
55 $ repo status
56
57## Using topic branches ##
58
59To assign the branch to a particular project:
60
61 $ repo start BRANCH_NAME PROJECT
62
63To switch to another branch that you have created in your local work environment:
64
65 $ git checkout BRANCH_NAME
66
67To see a list of existing branches:
68
69 $ git branch
70
71or
72
73 $ repo branches
74
75The name of the current branch will be preceded by an asterisk.
76
77*Note: A bug might be causing `repo sync` to reset the local topic branch. If `git branch` shows \* (no branch) after you run `repo sync`, then run `git checkout` again.*
78
79## Staging files ##
80
81By 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".
82
83You can stage your changes by running
84
85 git add
86
87which accepts as arguments any files or directories within the project directory. Despite the name, `git add` does not simply add files to the git repository; it can also be used to stage file modifications and deletions.
88
89## Viewing client status ##
90
91To list the state of your files:
92
93 $ repo status
94
95To see uncommitted edits:
96
97 $ repo diff
98
99The `repo diff` command 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:
100
101 $ cd ~/WORKING_DIRECTORY/PROJECT
102 $ git diff --cached
103
104## Committing changes ##
105
106A 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 typing
107
108 git commit
109
110You 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.
111
112## Uploading changes to Gerrit ##
113
114Before uploading, update to the latest revisions:
115
116 repo sync
117
118Next run
119
120 repo upload
121
122This 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/n` prompt.
123
124## Recovering sync conflicts ##
125
126If a `repo sync` shows sync conflicts:
127
128- View the files that are unmerged (status code = U).
129- Edit the conflict regions as necessary.
130- Change into the relevant project directory, run `git add` and `git commit` for the files in question, and then "rebase" the changes. For example:
131
132 $ git add .
133 $ git commit
134 $ git rebase --continue
135
136- When the rebase is complete start the entire sync again:
137
138 $ repo sync PROJECT0 PROJECT1 ... PROJECTN
139
140## Cleaning up your client files ##
141
142To update your local working directory after changes are merged in Gerrit:
143
144 $ repo sync
145
146To safely remove stale topic branches:
147
148 $ repo prune
149
150## Deleting a client ##
151
152Because all state information is stored in your client, you only need to delete the directory from your filesystem:
153
154 $ rm -rf WORKING_DIRECTORY
155
156Deleting a client will *permanently delete* any changes you have not yet uploaded for review.
157
158# Git and Repo cheatsheet #
159
160<img src="/images/git-repo-1.png">
161
162