开云电子(2023已更新)_IOS/安卓最新版
咨询热线:400-123-4657
网站公告: 诚信为本,市场在变,诚信永远不变...

24小时全国服务热线

400-123-4657

如果您有任何疑问或是问题, 请随时与我们联系

查看联系方式>>
第三系列 当前位置: 首页 > 产品中心 > 第三系列

博鱼体育app官网:Git-建立操作

点击量:456    时间:2023-05-10

本文摘要:在本章中,我们将相识如何建立远程Git存储库。

在本章中,我们将相识如何建立远程Git存储库。从现在开始,我们将其称为Git Server。

我们需要一个Git服务器来允许团队协作。建立新用户# add new group[root@CentOS ~]# groupadd dev# add new user[root@CentOS ~]# useradd -G devs -d /home/gituser -m -s /bin/bash gituser# change password[root@CentOS ~]# passwd gituser上面的下令将发生以下效果。

Changing password for user gituser.New password:Retype new password:passwd: all authentication token updated successfully.建立一个裸堆栈让我们通过使用init下令以及--bare选项来初始化一个新的存储库。它在没有事情目录的情况下初始化存储库。根据老例,裸堆栈必须命名为.git。

[gituser@CentOS ~]$ pwd/home/gituser[gituser@CentOS ~]$ mkdir project.git[gituser@CentOS ~]$ cd project.git/[gituser@CentOS project.git]$ ls[gituser@CentOS project.git]$ git --bare initInitialized empty Git repository in /home/gituser-m/project.git/[gituser@CentOS project.git]$ lsbranches config description HEAD hooks info objects refs生成公共/专用RSA密钥对让我们逐步完成设置Git服务器的历程,ssh-keygen实用法式将生成公用/专用RSA密钥对,将用于用户身份验证。打开一个终端并输入以下下令,然后为每个输入按Enter。乐成完成后,它将在主目录中建立一个.ssh目录。

tom@CentOS ~]$ pwd/home/tom[tom@CentOS ~]$ ssh-keygen上面的下令将发生以下效果。Generating public/private rsa key pair.Enter file in which to save the key (/home/tom/.ssh/id_rsa): Press Enter OnlyCreated directory '/home/tom/.ssh'.Enter passphrase (empty for no passphrase): ---------------> Press Enter OnlyEnter same passphrase again: ------------------------------> Press Enter OnlyYour identification has been saved in /home/tom/.ssh/id_rsa.Your public key has been saved in /home/tom/.ssh/id_rsa.pub.The key fingerprint is:df:93:8c:a1:b8:b7:67:69:3a:1f:65:e8:0e:e9:25:a1 tom@CentOSThe key's randomart image is:+--[ RSA 2048]----+| || || ||.|| Soo || o*B. || E = *.= || oo==. . || ..+Oo|+-----------------+ssh-keygen已经生成了两个密钥,第一个是私有的(即id_rsa),第二个是公共的(即id_rsa.pub)。注意:切勿与他人共享您的私钥。

将密钥添加到authorized_keys假设有两个开发人员在一个项目上事情,划分是Tom和Jerry。两个用户都生成了公共密钥。

让我们看看如何使用这些密钥举行身份验证。Tom通过使用ssh-copy-id下令将其公共密钥添加到服务器,如下所示-[tom@CentOS ~]$ pwd/home/tom[tom@CentOS ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub gituser@git.server.com上面的下令将发生以下效果。

gituser@git.server.com's password:Now try logging into the machine, with "ssh 'gituser@git.server.com'", and check in:.ssh/authorized_keysto make sure we haven't added extra keys that you weren't expecting.同样,Jerry通过使用ssh-copy-id下令将其公钥添加到服务器。[jerry@CentOS ~]$ pwd/home/jerry[jerry@CentOS ~]$ ssh-copy-id -i ~/.ssh/id_rsa gituser@git.server.com上面的下令将发生以下效果。gituser@git.server.com's password:Now try logging into the machine, with "ssh 'gituser@git.server.com'", and check in:.ssh/authorized_keysto make sure we haven't added extra keys that you weren't expecting.将更改推送到存储库我们在服务器上建立了一个裸堆栈,并允许两个用户会见。

从现在开始,Tom和Jerry可以通过将其更改添加为存储库来将其更改推送到存储库。Git init下令每次从.git / config文件中读取设置时,都市建立.git目录来存储有关存储库的元数据。

Tom建立一个新目录,添加README文件,并将其更改作为初始提交。提交后,他通过运行git log下令验证提交消息。[tom@CentOS ~]$ pwd/home/tom[tom@CentOS ~]$ mkdir tom_repo[tom@CentOS ~]$ cd tom_repo/[tom@CentOS tom_repo]$ git initInitialized empty Git repository in /home/tom/tom_repo/.git/[tom@CentOS tom_repo]$ echo 'TODO: Add contents for README' > README[tom@CentOS tom_repo]$ git status -s?? README[tom@CentOS tom_repo]$ git add .[tom@CentOS tom_repo]$ git status -sA README[tom@CentOS tom_repo]$ git commit -m 'Initial commit'上面的下令将发生以下效果。[master (root-commit) 19ae206] Initial commit1 files changed, 1 insertions(+), 0 deletions(-)create mode 100644 READMETom通过执行git log下令检查日志消息。

[tom@CentOS tom_repo]$ git log上面的下令将发生以下效果。commit 19ae20683fc460db7d127cf201a1429523b0e319Author: Tom Cat Date: Wed Sep 11 07:32:56 2013 +0530Initial commit汤姆将更改提交到当地存储库。

现在,是时候将更改推送到远程存储库了。可是在此之前,我们必须将存储库添加为远程存储库,这是一次性操作。今后,他可以宁静地将更改推送到远程存储库。

注 –默认情况下,Git仅推送到匹配的分支:对于当地存在的每个分支,如果已经存在相同名称的分支,则将更新远程端。在我们的教程中,每次我们将更改推送到Origin master分支时,请凭据您的要求使用适当的分支名称。[tom@CentOS tom_repo]$ git remote add origin gituser@git.server.com:project.git[tom@CentOS tom_repo]$ git push origin master上面的下令将发生以下效果。Counting objects: 3, done.Writing objects: 100% (3/3), 242 bytes, done.Total 3 (delta 0), reused 0 (delta 0)To gituser@git.server.com:project.git* [new branch]master −> master。


本文关键词:博鱼体育app官网

本文来源:博鱼体育app官网-www.businessplanmodule.com

【返回列表页】
地址:浙江省宁波市铁锋区仁筑大楼8998号    电话:400-123-4657    传真:+86-123-4567
Copyright © 2000-2023 www.businessplanmodule.com. 博鱼体育app官网科技 版权所有     ICP备70954835号-4