linux_git_码云上创建

来源:互联网 发布:淘宝开通直播入口 编辑:程序博客网 时间:2024/06/05 19:51

来自:www.kansnow.com

一、在码云上创建项目

简要说明

1.创建码云账号

https://gitee.com/

2.创建项目



在码云上既可以用git管理也可以用SVN管理。

说明:

归属既可以归属个人也可以归属组织,开源协议玩Linux嵌入式的一般选择GPL V2协议
是否公开,是就是允许别人下载观看,否就是只能自己或者是组织可以看或者下载。点击创建。

码云上默认是git管的使用SVN管理需要自己在 管理 那里设置。

删除项目也在管理那里操作。

二、码云公钥管理

开发者向码云版本库写入最常用到的协议是 SSH 协议,因为 SSH 协议使用公钥认证,可以实 现无口令访问,而若使用 HTTPS 协议每次身份认证时都需要提供口令。

1.Linux上对git进行全局配置

该配置只需做一次且对该Linux主机上所有git管理项目生效:

[zhoupiaolong@localhost ~ ]$ git config --global user.name "zhoupiaolong"[zhoupiaolong@localhost ~]$ git config  --global user.email "zhoupiaolong@gmail.com"

2.Linux上生成SSH key

用RSA公钥加密算法:

[zhoupiaolong@localhost ~]$ ssh-keygen -t rsa -C "zhoupiaolong@gmail.com"Generating public/private rsa key pair. Enter file in which to save the key (/home/guowenxue/.ssh/id_rsa):   按回车 /home/guowenxue/.ssh/id_rsa already exists. Overwrite (y/n)? yEnter passphrase (empty for no passphrase):  按回车Enter same passphrase again:  按回车Your identification has been saved in /home/guowenxue/.ssh/id_rsa.     私钥 Your public key has been saved in /home/guowenxue/.ssh/id_rsa.pub.   公钥The key fingerprint is:ae:49:19:71:99:53:de:f3:97:1d:86:e4:ab:ac:f6:54 zhoupiaolong@gmail.comThe key's randomart image is:+--[ RSA 2048]----+|          .  .   ||         = .o .  ||      . = . oo o ||       o .   oo +|...

3.上传Public Key

查看public key并拷贝,将他添加到码云个人帐号的SSH公钥里:

[zhoupiaolong@localhost ~]$ cat ~/.ssh/id_rsa.pubGT0jy4Bw6dhLbH7M3QBimWSDT3ZbYVBqL/KCX/4tz/vFXfGGyuYquY21WSGpRV+SDWT9e4ZEK6c0/Y2FxbRJ8/Vcw1IRFCi+PrCJEbfHqG5pvo2WrWAnXFE38RLiX8UJwj8cxTQJl4QaabEmclTtNmtpQsiFRddZ7ezhvU8Ml01AkA5QkkT

把命令下面的一连串代码复制到码云的SSH公钥上面。

4.​公钥添加测试

[zhoupiaolong@localhost ~]$  ssh -T git@git.oschina.netThe authenticity of host 'git.oschina.net (120.55.226.24)' can't be established.RSA key fingerprint is e3:ee:82:78:fb:c0:ca:24:65:69:ba:bc:47:24:6f:d4.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'git.oschina.net,120.55.226.24' (RSA) to the list of known hosts.Welcome to Gitee.com, zhoupiaolong!

显示上面所示则表示你的公钥添加成功了。
不同Linux主机下可以复制这两个文件id_rsa id_rsa.pub到相应的主机上既可以使用。

[zhoupiaolong@localhost ~]$ cd .ssh[zhoupiaolong@localhost .ssh]$ lsid_rsa  id_rsa.pub  known_hosts[zhoupiaolong@localhost .ssh]$

5.git下载测试

[zhoupiaolong@localhost gitee]$ git clone git@gitee.com:kansnow/mayuntest.gitInitialized empty Git repository in /home/zhoupiaolong/gitee/mayuntest/.git/The authenticity of host 'gitee.com (120.55.226.24)' can't be established.RSA key fingerprint is e3:ee:82:78:fb:c0:ca:24:65:69:ba:bc:47:24:6f:d4.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'gitee.com' (RSA) to the list of known hosts.remote: Counting objects: 4, done.remote: Compressing objects: 100% (3/3), done.remote: Total 4 (delta 0), reused 0 (delta 0)Receiving objects: 100% (4/4), 6.97 KiB, done.[zhoupiaolong@localhost gitee]$ lsmayuntest

四、Linux上git的基本操作

1.本地clone码云上的操作

[zhoupiaolong@localhost mayuntest]$ git clone git@gitee.com:kansnow/mayuntest.gitInitialized empty Git repository in /home/zhoupiaolong/gitee/mayuntest/.git/The authenticity of host 'gitee.com (120.55.226.24)' can't be established.RSA key fingerprint is e3:ee:82:78:fb:c0:ca:24:65:69:ba:bc:47:24:6f:d4.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'gitee.com' (RSA) to the list of known hosts.remote: Counting objects: 4, done.remote: Compressing objects: 100% (3/3), done.remote: Total 4 (delta 0), reused 0 (delta 0)Receiving objects: 100% (4/4), 6.97 KiB, done.[zhoupiaolong@localhost gitee]$ lsmayuntest

2..创建FL2440项目源码结构

[zhoupiaolong@localhost mayuntest]$ mkdir git-fl2440[zhoupiaolong@localhost mayuntest]$ lsgit-fl2440  [zhoupiaolong@localhost mayuntest]$ cd git-fl2440/[zhoupiaolong@localhost mayuntest]$ mkdir -p {crosstool,bootloader,linux/{kernel,rootfs},driver,3rdparty,program,images}[zhoupiaolong@localhost mayuntest]$ ls3rdparty  bootloader  crosstool  driver  images  linux  program

3.本地创建文件并提交服务器

注意: git不能管理空文件夹,只能管理文件里面有内容的文件:

[zhoupiaolong@localhost mayuntest]$ cd crosstool/[zhoupiaolong@localhost crosstool]$ vim build.sh[zhoupiaolong@localhost crosstool]$ chmod a+x build.sh[zhoupiaolong@localhost crosstool]$ cd ../..

git提交新创建的文件到服务器:

[zhoupiaolong@localhost mayuntest]$ git add crosstool/fatal: Not a git repository (or any of the parent directories): .git/* 这时候需要 */[zhoupiaolong@localhost mayuntest]$ git initInitialized empty Git repository in /home/zhoupiaolong/gitee/mayuntest/git-fl2440/.git/[zhoupiaolong@localhost mayuntest]$ git add crosstool/build.sh[zhoupiaolong@localhost mayuntest]$zhoupiaolong@localhost mayuntest]$ git commit -m"add crosstool/built.sh"[master 82ea922] add crosstool/built.sh1 files changed, 1 insertions(+), 0 deletions(-)[zhoupiaolong@localhost mayuntest]$ git pushCounting objects: 7, done.Compressing objects: 100% (3/3), done.Writing objects: 100% (4/4), 346 bytes, done.Total 4 (delta 2), reused 0 (delta 0)To git@gitee.com:kansnow/mayuntest.git   c943cc2..82ea922  master -> master

4.文件修改提交:

[zhoupiaolong@localhost mayuntest]$ vim crosstool/build.sh[zhoupiaolong@localhost mayuntest]$ git diffdiff --git a/crosstool/build.sh b/crosstool/build.shindex a09fb55..14e4cf0 100755--- a/crosstool/build.sh+++ b/crosstool/build.sh@@ -1,5 +1,7 @@ #!/bin/bash++ #This shell script used to download crosstool-ng install binary and compile itCROSSTOOL=crosstool-ng-centos-LingYun-v1.0.0.binif [ ! -f ${CROSSTOOL} ] ; then

git提交修改后的文件到服务器

[zhoupiaolong@localhost mayuntest]$ git add crosstool/build.sh[zhoupiaolong@localhost mayuntest]$ git commit -m "update crosstool/build.sh,add two enterin this script"[master 0044464] update crosstool/build.sh,add two enterin this script1 files changed, 2 insertions(+), 0 deletions(-)[zhoupiaolong@localhost mayuntest]$ gip push-bash: gip: command not found[zhoupiaolong@localhost mayuntest]$ git pushCounting objects: 7, done.Compressing objects: 100% (3/3), done.Writing objects: 100% (4/4), 370 bytes, done.Total 4 (delta 2), reused 0 (delta 0)To git@gitee.com:kansnow/mayuntest.git   82ea922..0044464  master -> master

5.文件删除后同步

[zhoupiaolong@localhost mayuntest]$ rm -rf crosstool/[zhoupiaolong@localhost mayuntest]$ ls3rdparty  bootloader  driver  images  LICENSE  linux  mayuntest  program  README.md[zhoupiaolong@localhost mayuntest]$ git checkout .[zhoupiaolong@localhost mayuntest]$ ls crosstool/build.sh

碰壁:之前为了阅读方便再创建了一个fl2440的目录没有执行git clone git@gitee.com:kansnow/fl2440.git,之前拉到的是mayuntest的目录下[zhoupiaolong@localhost mayuntest]$ git clone git@gitee.com:kansnow/mayuntest.git导致了总是找不到路径而出错,例如大家注意在新创建一个新目录fl2400的时候一定要在fl2400目录执行git clone git@gitee.com:kansnow/fl2400.git语句,否则找不到路径。

git@gitee.com:kansnow/fl2400.git的路径由来。