当前位置:   article > 正文

【repo和git的基本用法】_if you want to change this, please re-run 'repo in

if you want to change this, please re-run 'repo init' with --config-name

刚进公司,需要去配置很多环境,如果涉及到拉代码、提交代码,就需要用到repo和git。为了防止新人跟我之前一样走了很多弯路,下面对这个做些简单的总结。

一.第一部分(拉代码->编译)

  1. 首先需要知道我们使用的gerrit网址,一般为http://192.168.xxx.xxx:8081或者是使用公司名的。

  2. 本地生成公钥

终端输入ssh-keygen,一路回车到底,gerrit右上角Sign In登录-->点击自己的姓名-->setting进入个人资料-->点击SSH Public keys-->add自己的公钥,保证能使用gerrit获取代码。公钥添加完成后,在终端的图形化界面里面执行ssh-add使公钥生效(ssh远程命令行里不需要这样)。

注:公钥位置/home/xxx/.ssh/id_rsa.pub,.ssh目录默认不可见,ctrl+H就可以看到了。
  • 1
  • 2
  • 3
  1. 配置本地repo环境
获取repo工具文件,用关键词repo找到一个repo_tool的git仓库,可能各个公司的操作方法有差异,我就简单说下我的操作。下面的1010xxxx是我自己的工号。192.168.xxx.xxx:xxxxx是公司用的:

git clone ssh://1010xxxx@192.168.xxx.xxx:xxxxx/repo_tool

mkdir ~/bin 在家目录下创建/bin文件夹,把repo_tool下的repo文件放到~/bin下

chmod 755 repo  赋予repo文件可执行权限

PATH=~/bin:$PATH  加入环境变量

编辑repo文件,把

REPO_URL = 'https://gerrit.googlesource.com/git-repo'
REPO_REV = 'stable'

修改为

REPO_URL='ssh://1010xxxx@192.168.xxx.xxx:xxxxx/repo'
REPO_REV='master'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  1. 本地config配置
git config --global user.name 你的名字拼音

git config --global user.email 你的邮箱

git config --global review."192.168.xxx.xxx:8081".username 你的工号  ---->192.168.xxx.xxx:8081使用你正在使用的gerrit
  • 1
  • 2
  • 3
  • 4
  • 5
  1. 初始化manifest仓库,这个拉代码的指令公司会给出的,每个项目都不一样,这里就不详细写了。可以新建一个工程文件夹,右键打开终端,输入:
repo init --no-repo-verify -u ssh://xxxxxx
  • 1

当提示下面的格式,在本地新建文件夹看到一个.repo的文件夹,说明repo初始化是成功的:

Get ssh://1010xxxx@192.168.xxx.xxx:xxxxx/8X09/manifest

remote:Counting objects:20,done

remote:Finding sources:100%(20/20)

remote:Total 20 (delta 7),reused 18 (delta 7)

Unpacking objects:100%(20/20),done.

From ssh://192.168.xxx.xxx:xxxxx/8X09/manifest

 *[new branch]    master    ->origin/master

Your identity is:xxxxxxxxxxxxxxx

If you want to change this,please re-run 'repo init' with --config-name

repo has been initialized in /home/queen/1/test
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

在.repo下面有个manifest文件夹,是管理xml文件的仓库。manifest.xml是一个软链接指向真正的xml文件,project下面是所有的小的git裸仓库。

  1. 同步代码
repo sync 把所有的git仓库拉下来,可以在后面跟-c -jxx
  • 1
  1. 编译
./mk full_xxx_eng bootimage  后面接bootimage就只编一个boot,接new就是全编译具体看不同的项目,./mk r android就是只编安卓。比如有的项目编译指令就是make bootimage等,这个公司一般会说明。
  • 1

二. 第二部分(提交代码)

  1. 一般拉完代码最好先整体建立一个分支,以后就在这个分支上提交代码。
repo start --all xxx(分支名)
  • 1
  1. 查看提交的内容
git status . 可以查看修改了哪些文件

git diff . 可以查看具体修改了的内容

repo sync -c 同步

git log 查看自己以及别人commit的内容

git add xxx 之前git status .后看到的修改,可以把需要commit的add进去

git commit 可以commit分支上的内容

repo upload 上传
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

另外,还有很多命令这个流程有时用不到我在这里就不描述了,commit的内容不同公司有不同的要求,如果写错了需要修改也可以git commit --amend修改后再load,有的项目代码风格有要求,commit之后需要检查以及修改,需要打patch,使用git push上传,这里也不多说了。对这篇文章有什么问题也可以留言,看到了我会回复。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/56292
推荐阅读
相关标签
  

闽ICP备14008679号