網站首頁 編程語言 正文
一、Git 簡介
Git 是一款開源的分布式版本控制系統,可以有效、高效的處理從很小到非常大的項目版本管理。Git 是 Linux Torvalds 為了幫助管理 Linux 內核開發而開發的一個開放源代碼的版本控制軟件。
官網:https://git-scm.com/
1.Git 特點
優點:
- 適合分布式開發,強調個體;
- 公共服務器壓力和數據量都不會太大;
- 速度快、靈活;
- 離線工作;
缺點:
代碼保密性差,一旦開發者把整個庫克隆下來就可以完全公開所有代碼和版本信息;權限控制不友好;如果需要對開發者限制各種權限的建議使用 SVN。
2.版本控制器
簡單來說就是用來存放代碼的。
版本控制器分為:SVN(集中式的版本控制器),Git(分布式的版本控制器)
3.Git 工作流程
簡單來說就是在工作區上寫代碼,當要提交時,需要先將代碼上傳到暫存區,接著才可以將代碼提交到本地倉庫,當提交到本地倉庫后,還可以將代碼上傳到遠程倉庫,來供其它人訪問。
Git 的幾種狀態: 已暫存、已修改、已提交。
4.Git 的幾個核心概念
- 工作區:就是你平常存放項目代碼的地方。
- 暫存區:用于臨時存放你的改動,事實上它只是一個文件,保存即將提交到文件列表信息。
- 本地倉庫(版本庫):就是安全存放數據的位置,這里面都是你提交的所有代碼信息。
- 遠程倉庫:就是托管代碼的服務器,類似于 FTP 服務,能夠共享數據。
二、基于 Linux 部署 Git 服務器
準備工作
主機名 | 操作系統 | IP 地址 |
---|---|---|
Git | CentOS 7.4 | 192.168.1.1 |
Client | CentOS 7.4 | 192.168.1.2 |
1.Git 使用
創建用戶
[root@Git-Server ~]# useradd git # 創建 Git 用戶
[root@Git-Server ~]# echo "123456" | passwd git --stdin # 創建密碼
[root@Git-Server ~]# su - git # 切換到 Git 用戶
創建倉庫
[git@Git-Server ~]$ mkdir project # 創建目錄. 用于存放長倉庫
[git@Git-Server ~]$ cd project/
[git@Git-Server project]$ git init --bare # 初始化倉庫
2.驗證
在 Client 主機上創建工作目錄
[root@Client ~]# mkdir git
拉取庫到本地
[root@Client ~]# cd git/
[root@Client git]# git clone git@192.168.1.1:/home/git/project # 克隆
正克隆到 'project'...
git@192.168.1.1's password: # 輸入 Git 用戶的密碼
warning: 您似乎克隆了一個空版本庫。
[root@Client git]# ls # 查看項目
project
本地給新項目添加文件
[root@Client git]# cd project/ # 進入項目路徑
[root@Client project]# touch 1.txt # 創建測試文件
添加到暫緩區
[root@Client project]# git add .# 當前目錄內容都會添加
查看文件狀態
[root@Client project]# git status
提交到本地倉庫
[root@Client project]# git commit -m "Test"# -m 選項是說明信息
配置賬號和郵件
[root@Client project]# git config --global user.name "ZhangSan"
[root@Client project]# git config --global user.email "ZhangSan@163.com"
重新提交修改到本地倉庫
[root@Client project]# git commit -m 'Test'
確認本地倉庫和遠程倉庫的狀態是否正常
[root@Client project]# git remote add origin git@192.168.1.1:/home/git/project.git
fatal: 遠程 origin 已經存在。
把本地倉庫代碼推送到遠程倉庫
[root@Client project]# git push origin master
三、使用 GitHub
GitHub 是一個面向開源及私有軟件項目的托管平臺,因為只支持 Git 作為唯一的版本倉庫格式進行托管,所以故名為 GitHub。
1.注冊賬號
首先在官網上注冊一個賬號:https://github.com/
2.在客戶端上生成密鑰對
[root@Client ~]# ssh-keygen -t rsa # 創建密鑰對 (連敲三次回車即可)
[root@Client ~]# cat .ssh/id_rsa.pub # 查看公鑰
3.導入公鑰密鑰到 GitHub
登錄驗證
[root@Client ~]# ssh -T git@github.com # 需要聯網狀態
...
Are you sure you want to continue connecting (yes/no)? yes
...
Hi ChenZhuang1217! You've successfully authenticated, but GitHub does not provide shell access.
4.創建儲存空間
5.將本地項目上傳到 GitHub
[root@Client ~]# mkdir Test
[root@Client ~]# cd Test/
[root@Client Test]# echo "This is Test" > README.md
[root@Client Test]# git init
初始化空的 Git 版本庫于 /root/Test/.git/
[root@Client Test]# git add README.md
[root@Client Test]# git commit -m "First Commit"
[root@Client Test]# git remote add origin git@github.com:ChenZhuang1217/Test.git
fatal: 遠程 origin 已經存在。
[root@Client Test]# git push -u origin master
6.查看 GitHub 文件
7.同步遠程倉庫的最新狀態到本地倉庫
在 GitHub 創建新的文件
在本地倉庫中拉取遠程倉庫的文件
[root@Client Test]# git pull -u origin master
原文鏈接:https://blog.csdn.net/weixin_46902396/article/details/118188953
相關推薦
- 2022-11-03 C/C++預處理淺析使用形式_C 語言
- 2022-06-10 解決Qt設置QTextEdit行高的問題_C 語言
- 2022-10-15 Docker數據卷掛載命令volume(-v)與mount的使用總結_docker
- 2022-06-12 如何在React項目中使用AntDesign_React
- 2023-03-28 python程序中調用其他程序的實現_python
- 2022-08-31 Python?selenium?find_element()示例詳解_python
- 2022-10-01 Go編譯原理之函數內聯_Golang
- 2022-07-21 數據庫慢查詢介紹并優化
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支