Git与Repo基础教程:Android源码管理

需积分: 49 24 下载量 160 浏览量 更新于2024-09-13 收藏 204KB DOC 举报
"Git_和repo扫盲" Git与repo是Android开发中不可或缺的工具,用于管理和协作开发。Git是一款由Linux Torvalds开发的分布式版本控制系统,它的设计目标是高效、快速地处理大型项目,即使在没有网络连接的情况下也能正常工作。与传统的集中式版本控制系统(如Subversion和CVS)不同,Git的每个工作副本都是一个完整的仓库,拥有项目的历史记录和分支,这使得开发者可以在本地进行提交和合并,之后再将更改推送到中央服务器。 在Android开发场景中,由于项目由多个不同的Git仓库(如kernel、Dalvik、Bionic、prebuilt、build等)组成,单纯使用Git可能会变得复杂。为此,Google开发了一个名为Repo的Python脚本,它作为Git的一个前端,用来简化对这些仓库的管理。Repo能够帮助开发者一次性处理多个Git仓库,同步、创建分支和合并代码变得更加方便。 安装Git通常可以通过包管理器完成,例如在Ubuntu 8.04上,可以使用以下命令安装: ```bash sudo apt-get install git-core curl ``` Git的依赖工具cURL在这里也很重要,它用于下载Repo脚本。 安装Repo的步骤包括: 1. 确保在用户主目录下有/bin目录,并将其添加到PATH环境变量中: ```bash mkdir -p ~/bin export PATH=$PATH:~/bin ``` 2. 下载Repo脚本到~/bin目录,并赋予执行权限: ```bash curl https://android.googlesource.com/tools/repo.git/+/master/repo > ~/bin/repo chmod a+x ~/bin/repo ``` 3. 使用Repo初始化Android源码仓库: 进入工作目录,如~/android,然后运行: ```bash repo init -u https://android.googlesource.com/platform/manifest ``` 这会初始化一个包含所有Android源码的Git仓库集合。 4. 获取源码: 接着,使用Repo下载所有源码: ```bash repo sync ``` 这个过程可能需要一些时间,因为它会下载大量的代码和文件。 在日常开发中,Git和Repo的使用还包括创建分支、提交更改、合并分支以及推送更改到远程仓库等操作。例如,可以使用`git checkout -b <new_branch>`创建一个新的分支,`git add .`添加所有修改,`git commit -m "commit message"`提交更改,然后用`repo upload`或`git push`将更改推送到远程仓库。 Git和Repo的组合为Android开发提供了强大的版本控制和项目管理能力,使得开发者能够高效地协同工作,同时保持代码的整洁和一致性。熟悉并熟练使用这两个工具,对于任何参与Android开发的人员来说都是至关重要的。

Traceback (most recent call last): File "F:\conda\envs\yolov5\lib\site-packages\git\__init__.py", line 89, in <module> refresh() File "F:\conda\envs\yolov5\lib\site-packages\git\__init__.py", line 76, in refresh if not Git.refresh(path=path): File "F:\conda\envs\yolov5\lib\site-packages\git\cmd.py", line 392, in refresh raise ImportError(err) ImportError: Bad git executable. The git executable must be specified in one of the following ways: - be included in your $PATH - be set via $GIT_PYTHON_GIT_EXECUTABLE - explicitly set via git.refresh() All git commands will error until this is rectified. This initial warning can be silenced or aggravated in the future by setting the $GIT_PYTHON_REFRESH environment variable. Use one of the following values: - quiet|q|silence|s|none|n|0: for no warning or exception - warn|w|warning|1: for a printed warning - error|e|raise|r|2: for a raised exception Example: export GIT_PYTHON_REFRESH=quiet The above exception was the direct cause of the following exception: Traceback (most recent call last): File "E:\yolov5-master\train.py", line 67, in <module> GIT_INFO = check_git_info() File "F:\conda\envs\yolov5\lib\contextlib.py", line 79, in inner return func(*args, **kwds) File "E:\yolov5-master\utils\general.py", line 360, in check_git_info import git File "F:\conda\envs\yolov5\lib\site-packages\git\__init__.py", line 91, in <module> raise ImportError("Failed to initialize: {0}".format(exc)) from exc ImportError: Failed to initialize: Bad git executable. The git executable must be specified in one of the following ways: - be included in your $PATH - be set via $GIT_PYTHON_GIT_EXECUTABLE - explicitly set via git.refresh() All git commands will error until this is rectified. This initial warning can be silenced or aggravated in the future by setting the $GIT_PYTHON_REFRESH environment variable. Use one of the following values: - quiet|q|silence|s|none|n|0: for no warning or exception - warn|w|warning|1: for a printed warning - error|e|raise|r|2: for a raised exception Example: export GIT_PYTHON_REFRESH=quiet

2023-06-11 上传

Traceback (most recent call last): File "C:\Users\GL\.conda\envs\pytorch\lib\site-packages\git\__init__.py", line 89, in <module> refresh() File "C:\Users\GL\.conda\envs\pytorch\lib\site-packages\git\__init__.py", line 76, in refresh if not Git.refresh(path=path): File "C:\Users\GL\.conda\envs\pytorch\lib\site-packages\git\cmd.py", line 392, in refresh raise ImportError(err) ImportError: Bad git executable. The git executable must be specified in one of the following ways: - be included in your $PATH - be set via $GIT_PYTHON_GIT_EXECUTABLE - explicitly set via git.refresh() All git commands will error until this is rectified. This initial warning can be silenced or aggravated in the future by setting the $GIT_PYTHON_REFRESH environment variable. Use one of the following values: - quiet|q|silence|s|none|n|0: for no warning or exception - warn|w|warning|1: for a printed warning - error|e|raise|r|2: for a raised exception Example: export GIT_PYTHON_REFRESH=quiet The above exception was the direct cause of the following exception: Traceback (most recent call last): File "E:\eclipse workspace\yolov5-master\train.py", line 72, in <module> GIT_INFO = check_git_info() File "C:\Users\GL\.conda\envs\pytorch\lib\contextlib.py", line 79, in inner return func(*args, **kwds) File "E:\eclipse workspace\yolov5-master\utils\general.py", line 360, in check_git_info import git File "C:\Users\GL\.conda\envs\pytorch\lib\site-packages\git\__init__.py", line 91, in <module> raise ImportError("Failed to initialize: {0}".format(exc)) from exc ImportError: Failed to initialize: Bad git executable. The git executable must be specified in one of the following ways: - be included in your $PATH - be set via $GIT_PYTHON_GIT_EXECUTABLE - explicitly set via git.refresh() All git commands will error until this is rectified. This initial warning can be silenced or aggravated in the future by setting the $GIT_PYTHON_REFRESH environment variable. Use one of the following values: - quiet|q|silence|s|none|n|0: for no warning or exception - warn|w|warning|1: for a printed warning - error|e|raise|r|2: for a raised exception Example: export GIT_PYTHON_REFRESH=quiet

2023-07-10 上传

execute_process(COMMAND sh -c "git symbolic-ref --short -q HEAD" OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND sh -c "git rev-list HEAD --abbrev=8 --abbrev-commit --max-count=1" OUTPUT_VARIABLE GIT_LAST_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND sh -c "git rev-list HEAD --count" OUTPUT_VARIABLE GIT_COMMITS_NUM OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND sh -c "git status --short --untracked-files=no | wc -l" OUTPUT_VARIABLE GIT_DIFF_STATUS OUTPUT_STRIP_TRAILING_WHITESPACE) if ( ${GIT_DIFF_STATUS} EQUAL "0" ) set(BUILD_VERSION "R${GIT_LAST_COMMIT}_${GIT_BRANCH}") else() set(BUILD_VERSION "R${GIT_LAST_COMMIT}M_${GIT_BRANCH}") endif() #build date string(TIMESTAMP DATETIME "%Y%m%d%H%M%S") #enable gdb debug symbol if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") message (STATUS "No CMAKE_BUILD_TYPE selected, defaulting to ${CMAKE_BUILD_TYPE}") endif() message (STATUS "The CMAKE_BUILD_TYPE is selected to ${CMAKE_BUILD_TYPE}") set(CMAKE_CXX_FLAGS_BASE "$ENV{CXXFLAGS} -pipe -Wall -Wno-unknown-pragmas -Wno-format-zero-length -lrt -Wno-ignored-attributes") #set(CMAKE_CXX_FLAGS_BASE "${CMAKE_CXX_FLAGS_BASE} -save-temps") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_BASE} -O2 -g") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_BASE} -O3") #set(CMAKE_DEBUG_POSTFIX _D) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time") set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CMAKE_COMMAND} -E time")

2023-07-22 上传