(Transferred from http://source.android.com/source/git-repo.html, the company's network operator has questions, so you can view them in the company)
Using repo and git
To work with the android code, you will need to use both git and repo.
- 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.
- Repo
Is a tool that we built on top of git. Repo helps us manage the latest git repositories, 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
Context of Android. The repocommand is an executable Python script that
You can put anywhere in your path.
In working with the android source files, you will use Repo
Using SS-network operations. For example, with a single repo command you
Can download files from multiple repositories into your local working
Directory.
About git
Why git?
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
Distributed revision control system, then further narrowed it down
Git.
Already a git user?
In most situations, you can use git instead of Repo, or mix repo and git
Commands to form complex commands. Using Repo for basic compute SS-network
Operations will make your work much simpler, however.
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 get Source
.
Installing Repo
$ Curl http://android.git.kernel.org/repo> ~ /Bin/Repo
$ Chmod A + x ~ /Bin/Repo
$ MkdirWorking-directory-name
$ CdWorking-directory-name
$ Repo init-u git: // android.git.kernel.org/platform/manifest.git
Synchronizing your client
To synchronize the files for all available projects:
$ Repo sync
To
Synchronize the files for selected projects:
$ Repo syncProject1
Project2...
Why use topic branches?
Start a topic branch in your local work environment whenever you begin
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
Particle commit. This makes creating local branches and switching
Among them a light-weight operation. By using branches, you
Canisolateone aspect of your work from the others. For an interesting
Article about using topic branches, see separating topic branches
.
Creating topic branches
To start a topic branch using repo:
$ Repo startBranchname
To verify that your new branch was created:
$ Repo status
Using topic branches
To assign the Branch to a special project:
$ Repo startBranch
Name Project
To switch back and forth among branches that you have created in your local work environment:
$ Git checkoutBranchname
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 sync to reset the local topic branch. If git
Branch shows * (no branch) after you run repo sync, then run git
Checkoutagain. Viewing client status
To list the state of your files:
$ Repo status
To see uncommitted edits:
$ Repo diff
Therepo diffcommand shows every local edit that you have made that wowouldNot
Go into the commit, if you were to commit right now.
To see every
Edit that wowould 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 down
In the project directory:
$ Cd ~ /Workingdirectory
/Project
$ Git diff -- cached
Recovering sync conflicts
If a repo sync shows 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 add and git
Commit for the files in question, and then "rebase" The changes.
Example:
$ CD bionic
$ Git add bionic /*
$ Git commit
$ Git rebase -- continue
- When the rebase is complete start the entire sync again:
$ Repo syncbionicProj2
Proj3
...Projn
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
Deleting a client willPermanently delete
Any changes you have not yet uploaded for review. becauseall state
Information is stored in your client, you only need to delete
Directory from your filesystem:
$ Cd~
$ Rm-RFWorking-directory-name
Scripting Common Tasks
You can use repo to run the same program into SS all projects:
$ Repo forall [Proj1
Proj2
...
Projn
]-C'Echo $ repo_project $ @
'[Arg1
Arg2
...
Argn
]
The-C argument is evaluated through/bin/sh and any arguments after it are passed through as shell positional parameters.
Repo command reference
Repo usage takes the following form:
RepoCommand Options
Optional elements are shown in brackets []. Once repo is installed, you can get information about any command by running
Repo helpCommand
Init
Repo init-uURL
[Options
]
Installrepo in the current directory. This creates
. Repo/directory that contains git repositories for the repo source code
And the standard Android manifest files. The. repo/directory also
Containsmanifest. XML, which is a symlink to the selected manifest in
. Repo/manifests/directory.
The-u argument specifies a URL from which to retrieve a manifest repository. For example:
$ Repo init-u git: // android.git.kernel.org/platform/manifest.git
To
Select a manifest file within the repository, use the-M option. (If NO
Manifest name is selected, the default is default. xml.) For example:
$ Repo init-ugit: // android.git.kernel.org/platform/manifest.git-m dalkvik-plus.xml
To specify a revision, that is, a special manifest-branch, use the-B option. For example:
$ Repo init-ugit: // android.git.kernel.org/platform/manifest.git-b release-1.0
To see other repo init options, run
$ Repo help init
Note:
For all remaining repo commands, the current working directory must
Either be the parent directory of. repo/or a subdirectory of the parent
Directory.
Sync
Repo sync [Project-list
]
Downloads new changes and updates the working files in
Your local environment. After a successful repo sync, the code in
Specified Projects will be up to date with the code in the remote
Repository.
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
Repo sync [Proj1
Proj2
...
Projn
]
If you run repo sync without any arguments, it will synchronize the files for all the projects.
How repo synchronization works
When you run repo sync, this is what happens:
- If the project has never been synchronized, then repo sync is
Equivalent to git clone. All branches in the remote repository are
Copied to the local project directory.
- If the project has already been synchronized once, then repo sync is equivalent:
Git remote update
Git rebase origin/Branch
WhereBranch
Is the currently checked-out branch in the local project directory. If
The local branch is not tracking a branch in the remote repository, then
No synchronization will occur for the project.If the GIT rebase
Operation results in merge conflicts, you will need to use the normal
Git commands (for example, git rebase -- continue) to resolve
Conflicts.
The repo sync command also updates the private repositories in the. repo/directory.
Upload
Repo upload [Project-list
]
For the specified projects, Repo compares the local
Branches to the remote branches updated during the last repo sync. Repo
Will prompt you to select one or more of the branches that have not yet
Been uploaded for review.
After you select one or more branches,
All commits on the selected branches are transmitted to Gerrit over
SSH connection. You will need to configure an SSH key to enable upload
Authorization. Visit SSH keys
Within the user settings panel to register your public keys
Gerrit. To enable password-less uploads, consider using SSH-agent on your
Client System.
When Gerrit hosts es the object data over its SSH
Server, it will turn each commit into a change so that reviewers can
Comment on each commit individually.
To combine several "checkpoint" commits together into a single commit, use git rebase-I before you run repo upload.
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
Repo upload [Proj1
Proj2
...
Projn
]
If you run repo upload without any arguments, it will search all the projects for changes to upload.
To
Make edits to changes after they have been uploaded, you shoshould use
Tool likegit rebase-ior git commit -- Amend to update your local
Commits.
After your edits are complete:
- Make sure the updated branch is the currently checked out branch.
- Use repo upload -- replaceProj1
To open the change matching editor.
- For each commit in the series, enter the Gerrit change ID inside the brackets:
# Replacing from Branch foo
[1, 3021] 35f2596c refactor part of getuploadablebranches to lookup one specific...
[2829] ec18b4ba update proto client to support Patch Set replacments
[3022] c99883fe teach 'repo upload -- replace 'how to add replacement patch se...
# 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 (e.g. Patch Set 2, Patch Set 3 ,...).
Diff
Repo diff [Project-list
]
Shows changes between commit and working tree.
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
Repo diff [Proj1
Proj2
...
Projn
]
Options:
-H, -- helpmeans show this help message and exit.
Download
Repo downloadTarget
Change
Downloads the specified change into the specified local directory. (Added to repo as of version 1.0.4 .)
For example, to download change 1241
Into your platform/frameworks/base directory:
$ Repo download platform/frameworks/base 1241
A "Repo
Sync "shocould could fetch tively remove any commits retrieved via" Repo
Download ". Or, you can check out the remote branch; e.g.," Git checkout
M/master ".
Note:
As of Jan. 26,200 9, there is a processing ing lag of approximately 5 minutes between when a change is visible on the Web in Gerrit
And when repo download will be able to find it, because changes are
Actually downloaded off the GIT: // android.git.kernel.org/mirror farm.
There will always be a slight loading ing lag as Gerrit pushes newly
Uploaded changes out to the mirror farm.
Forall
Repo forall [Project-list
]-CCommand
[Arg.
...]
Runs a shell command in each project.
You can specify project-list as a list of names or a list of paths to local source directories for the projects
Help
Repo help [Command
]
Displays Detailed Help about a command.
Prune
Repo prune [Project-list
]
Prunes (deletes) topics that are already merged.
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
Repo prune [Proj1
Proj2
...
Projn
]
Start
Repo startNewbranchname
[Project-list
]
Starts a new branch for development.
TheNewbranchname
Argument shoshould 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.
TheProject-list
Specifies which projects will participate in this topic branch. You can
Specify project-list as a list of names or a list of paths to local
Working directories for the projects:
Repo start default [Proj1
Proj2
...
Projn
]
"." Is a useful shorthand for the project in the current working directory.
Status
Repo status [Project-list
]
Shows the status of the current working directory. You can
Specify project-list as a list of names or a list of paths to local
Source directories for the projects:
Repo status [
Proj1
Proj2
...
Projn
]
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 left-most column, an uppercase letter indicates what
Is happening in the index (the staged files) when compared to the last
Committed state.
- In the next column, a lowercase letter indicates what is happening
In the working directory when compared to the index (what is staged ).
Character |
Meaning |
A |
The file is added (brand new). can only appear in the first column. |
M or m |
The file already exists but has been modified in some way. |
D Or d |
The file has been deleted. |
R |
The file has been renamed. can only appear in the first column. The new name is also shown on the line. |
C |
The file has been copied from another file. can only appear in the first column. The source is also shown. |
T |
Only the file's mode (executable or not) has been changed. can only appear in the first column. |
U |
The file has merge conflicts and is still unmerged. can only appear in the first column. |
- |
The file state is unmodified. A hyphen inBoth Columns means this is a new file, unknown to git. After you run git add On this file, Repo status will show a-, indicating the file has been Added. |
For example, if you edit the file main. py within the appeng project without staging the changes, then repo status might show
Project appeng/
-MMain. py
If you go on to stage the changes to main. py by running git add, then repo status might show
Project appeng/
M-Main. py
If
You then make further edits to the already-staged main. py and make
Edits to another file within the project, app. yaml, then repo status
Might show
Project appeng/
-Mapp. yaml
MM main. py
Git and repo cheatsheet
Click on the cheatsheet to open it in a new window for easier printing.
Terminology
Staged
Changes
Changes marked by git add for future sion in the next commit's snapshot.
Commit
At intervals, you use git commit to save a snapshot of the staged files and a log message that describes the change.
Manifest
A manifest file that contains a list of repositories and a mapping
Of where the files from these repositories will be located within your
Working directory. When you synchronize your files, the files contained
In the repositories that are listed in the manifest will be pulled
Your working directory.