git repo tool detailed tutorial

Introduction to repo

What is a repo?

Repo is a tool developed by Google for managing Android repositories. Repo uses Python to encapsulate git to a certain extent. It is not used to replace git. It simplifies the management of multiple Git repositories. The version library managed by repo needs to use the git command to operate. Therefore, before using the repo tool, please ensure that git is installed.
repo is a tool for managing multiple Git repositories, which can help you manage the code of multiple Git repositories in one code base.

Why use repo?

After the project is modularized/componentized, each module is also separated from the main project as an independent Git repository, and each module manages its own version. The Android source code refers to many open source projects. Each sub-project is a Git repository, and each Git repository has many branch versions. In order to facilitate the unified management of the Git repositories of each sub-project, an upper-level tool is needed for batch processing, so repo was born. .
Repo will also create a Git warehouse to record which branch the Git warehouse of each sub-project under the current Android version is in. This warehouse is usually called: manifest warehouse (list library).

Use of repo

repo download and install

Download address: https://mirrors.tuna.tsinghua.edu.cn/git/git-repo, name the downloaded file repo, and place it under the directory contained in the PATH environment variable, for example, it can be placed in /usr/ local/bin directory (the following descriptions will be placed in the /usr/local/bin directory as an example).
Alternatively, download directly using the curl command:

plaintextCopy code$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo


The above command will download and install the repo script in your ~/bin directory.

Initialize the codebase

Before using a repo, you need to initialize a code repository on your local machine and
associate it with the repo. On your local machine, create a directory and initialize the repository:

plaintextCopy code$ mkdir myproject
$ cd myproject
$ repo init -u <URL>

where
is the URL of the Git repository you want to use. This will create a .repo directory in the current directory
and
download the configuration file for the repo tool into that directory.

synchronous code

Once you have initialized the repository, you can sync the code locally with the following command:

plaintextCopy code$ repo sync

This will
automatically download and update the code in all Git repositories using the repo tool.

Manage Git repositories

Use the repo start command to create a new branch, then use
the repo upload command to commit the changes to the code review tool. You can also
execute arbitrary Git commands across all Git repositories with the repo forall command.

update code

You can update all Git repositories in your codebase with the following command:

plaintextCopy code$ repo sync

This will download and update the code in all Git repositories. The above is
the basic usage introduction of repo. Using repo makes it easier to manage multiple Git repositories and enables you to more conveniently do code sharing and code review.

View code update history under repo management

If you use repo to manage multiple Git repositories, you can use the following command to view the modification records of the entire code base in repo:

plaintextCopy coderepo forall -c 'git log'

This will output its Git log for each Git repository. You can also use the following command to view the modification records of a specific repository:

plaintextCopy coderepo forall <project_name> -c 'git log'

where <project_name> is the name of the specific repository you want to view. Please note that repo is just a tool for managing multiple Git repositories. It does not store code itself, so you cannot directly view the modification records of the entire code base.

Guess you like

Origin blog.csdn.net/yikezhuixun/article/details/129426036