大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 hot資訊 Git創建操作步驟

Git創建操作步驟

更新時間:2021-12-23 11:33:17 來源:動力節點 瀏覽1670次

在本章中,我們將看到如何創建遠程 Git 存儲庫;從現在開始,我們將把它稱為 Git 服務器。我們需要一個 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 init
Initialized empty Git repository in /home/gituser-m/project.git/
[gituser@CentOS project.git]$ ls
branches config description HEAD hooks info objects refs

生成公共/私人 RSA 密鑰對

讓我們來看看配置 Git 服務器的過程,ssh-keygen實用程序會生成公鑰/私鑰 RSA 密鑰對,我們將使用它來進行用戶身份驗證。

打開終端并輸入以下命令,然后為每個輸入按回車鍵。成功完成后,它將在主目錄中創建一個.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 Only
Created directory '/home/tom/.ssh'.
Enter passphrase (empty for no passphrase): ---------------> Press Enter Only
Enter same passphrase again: ------------------------------> Press Enter Only
Your 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@CentOS
The 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 [email protected]

上述命令將產生以下結果。

[email protected]'s password:
Now try logging into the machine, with "ssh '[email protected]'", and check in:
.ssh/authorized_keys
to 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 [email protected]

上述命令將產生以下結果。

[email protected]'s password:
Now try logging into the machine, with "ssh '[email protected]'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.

將更改推送到存儲庫

我們在服務器上創建了一個裸存儲庫,并允許兩個用戶訪問。從現在開始,Tom 和 Jerry 可以通過將其添加為遠程來將他們的更改推送到存儲庫。

每次從.git/config文件讀取配置時,Git init 命令都會創建.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 init
Initialized 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 -s
A README
[tom@CentOS tom_repo]$ git commit -m 'Initial commit'

上述命令將產生以下結果。

[master (root-commit) 19ae206] Initial commit
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 README

Tom 通過執行 git log 命令檢查日志消息。

[tom@CentOS tom_repo]$ git log

上述命令將產生以下結果。

commit 19ae20683fc460db7d127cf201a1429523b0e319
Author: Tom Cat <[email protected]>
Date: Wed Sep 11 07:32:56 2013 +0530
Initial commit

Tom 將他的更改提交到本地存儲庫?,F在,是時候將更改推送到遠程存儲庫了。但在此之前,我們必須將存儲庫添加為遠程,這是一次性操作。在此之后,他可以安全地將更改推送到遠程存儲庫。

注意- 默認情況下,Git 僅推送到匹配的分支:對于本地端存在的每個分支,如果遠程端已存在同名分支,則會更新遠程端。在我們的教程中,每次我們將更改推送到原始主分支時,請根據您的要求使用適當的分支名稱。

[tom@CentOS tom_repo]$ git remote add origin [email protected]: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 [email protected]:project.git
* [new branch]
master ?> master

現在,更改已成功提交到遠程存儲庫。如果您想了解更多相關知識,不妨來關注一下動力節點的Java在線學習,里面的內容全面細致,由淺到深,適合小白學習,希望對大家能夠有所幫助。

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 99视频国产热精品视频 | 91亚洲精品国产自在现线 | 久久www免费人成精品香蕉 | 欧美一级α片毛片免费观看 | 日韩专区亚洲精品欧美专区 | 国产亚洲欧美久久精品 | 亚洲九九爱 | 精品国产线拍大陆久久尤物 | 中文字幕日本在线观看 | chinese国产在线视频 | 99久久国产综合精麻豆 | 精品一区二区三区的国产在线观看 | 午夜网站在线观看免费网址免费 | 免费观看欧美一级高清 | 色视频网| 大美女久久久久久j久久 | 国产成人禁片免费观看视频 | 亚洲免费观看 | 国产天天操| 三中文乱码视频 | jizz成熟丰满老女人 | 涩涩免费视频 | 亚洲国产高清美女在线观看 | 久久国内精品 | aaaa视频| 免费高清在线影片一区 | 久久riav.com| 午夜影院普通 | 国产免费一区二区三区免费视频 | 色视频久久 | 亚洲成a | 久草免费在线视频 | 国产午夜精品一区二区三区嫩草 | 欧美videos肥婆hd | 99热久久只有精品99只有精品 | 精品久久久久久中文字幕欧美 | 97在线视频免费公开观看 | 一级毛片看一个 | 97视频在线观看免费 | 国产综合色在线视频区色吧图片 | 天堂一区二区三区精品 |