blob: 302fb68f540faba724d9dba71179e003f4fc8e22 [file] [log] [blame] [view]
Skyler Kaufman44436912011-04-07 15:11:52 -07001<!--
2 Copyright 2010 The Android Open Source Project
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15-->
16
Skyler Kaufman991ae4d2011-04-07 12:30:41 -070017# Version Control with Repo and Git #
18
19To 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.
20
21**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.
22
Jean-Baptiste Queru0e3ee322012-01-11 05:42:17 -080023**Repo** is a repository management tool that we built on top of Git. Repo
24unifies the many Git repositories when necessary, does the uploads to our
25[revision control system](https://android-review.googlesource.com/), and
26automates parts of the Android development workflow. Repo is not meant to
27replace Git, only to make it easier to work with Git in the context of
28Android. The repo command is an executable Python script that you can put
29anywhere in your path. In working with the Android source files, you will
30use Repo for across-network operations. For example, with a single Repo
31command you can download files from multiple repositories into your local
32working directory.
Skyler Kaufman991ae4d2011-04-07 12:30:41 -070033
34**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.
35
36## Basic Workflow ##
37
38<div style="float:right">
Jean-Baptiste Queruf2596502011-11-18 16:54:31 -080039 <img src="/images/submit-patches-0.png" alt="basic workflow diagram">
Skyler Kaufman991ae4d2011-04-07 12:30:41 -070040</div>
41
42The basic pattern of interacting with the repositories is as follows:
43
441. Use `repo start` to start a new topic branch.
45
461. Edit the files.
47
481. Use `git add` to stage changes.
49
501. Use `git commit` to commit changes.
51
521. Use `repo upload` to upload changes to the review server.
53
54# Task reference #
55
56The task list below shows a summary of how to do common Repo and Git tasks.
57For complete quick-start information and examples, see [Getting started](downloading.html).
58
59## Synchronizing your client ##
60
61To synchronize the files for all available projects:
62
63 $ repo sync
64
65To synchronize the files for selected projects:
66
67 $ repo sync PROJECT0 PROJECT1 PROJECT2 ...
68
69## Creating topic branches ##
70
71Start 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).
Jean-Baptiste Queruf2596502011-11-18 16:54:31 -080072<img src="/images/external-link.png" alt="">
Skyler Kaufman991ae4d2011-04-07 12:30:41 -070073
74To start a topic branch using Repo:
75
76 $ repo start BRANCH_NAME
77
78To verify that your new branch was created:
79
80 $ repo status
81
82## Using topic branches ##
83
84To assign the branch to a particular project:
85
86 $ repo start BRANCH_NAME PROJECT
87
88To switch to another branch that you have created in your local work environment:
89
90 $ git checkout BRANCH_NAME
91
92To see a list of existing branches:
93
94 $ git branch
95
96or
97
98 $ repo branches
99
100The name of the current branch will be preceded by an asterisk.
101
102*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.*
103
104## Staging files ##
105
106By 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".
107
108You can stage your changes by running
109
110 git add
111
112which 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.
113
114## Viewing client status ##
115
116To list the state of your files:
117
118 $ repo status
119
120To see uncommitted edits:
121
122 $ repo diff
123
124The `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:
125
126 $ cd ~/WORKING_DIRECTORY/PROJECT
127 $ git diff --cached
128
129## Committing changes ##
130
131A 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
132
133 git commit
134
135You 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.
136
137## Uploading changes to Gerrit ##
138
139Before uploading, update to the latest revisions:
140
141 repo sync
142
143Next run
144
145 repo upload
146
147This 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.
148
149## Recovering sync conflicts ##
150
151If a `repo sync` shows sync conflicts:
152
153- View the files that are unmerged (status code = U).
154- Edit the conflict regions as necessary.
155- Change into the relevant project directory, run `git add` and `git commit` for the files in question, and then "rebase" the changes. For example:
156
157 $ git add .
158 $ git commit
159 $ git rebase --continue
160
161- When the rebase is complete start the entire sync again:
162
163 $ repo sync PROJECT0 PROJECT1 ... PROJECTN
164
165## Cleaning up your client files ##
166
167To update your local working directory after changes are merged in Gerrit:
168
169 $ repo sync
170
171To safely remove stale topic branches:
172
173 $ repo prune
174
175## Deleting a client ##
176
177Because all state information is stored in your client, you only need to delete the directory from your filesystem:
178
179 $ rm -rf WORKING_DIRECTORY
180
181Deleting a client will *permanently delete* any changes you have not yet uploaded for review.
182
183# Git and Repo cheatsheet #
184
Jean-Baptiste Queruf2596502011-11-18 16:54:31 -0800185<img src="/images/git-repo-1.png" alt="list of basic git and repo commands">
Skyler Kaufman991ae4d2011-04-07 12:30:41 -0700186
187