(一)、配置SSH到Gitlab帳號
一、使用ssh-keygen生成密鑰文件.ssh/id_rsa.pubhtml
[root@zabbix-proxy0496 ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:3DpddsSwRtOfMSDE8NSancZpL9sP7LPKFZQmjc2BWxc root@zabbix-proxy0496 The key's randomart image is: +---[RSA 2048]----+ | .++=+oE.| | ooo@o=.| | .Xo%o+| | . . +.% ..| | S . = + | | o o + o | | o . B | | . . +.o | | o.ooo| +----[SHA256]-----+
二、查看公鑰的配置密文git
[root@zabbix-proxy0496 ~]# cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJLYoootIWqpvrvuCpdCzSQGFHt/AYrXo5eYiqU6f2x8e55EjlOTMchykdBdZH0E38T7E/0GVD5J4Juo0F4TKXQAS0Vcg3MvDdaMyJRUBliN+CP8PjiTcKmLBXXnFTyr2d7XSLrkOq7EMf5PXpvl/SK+ildMC0YKNm2bDcg6hTRdWMoSC9dqUY/xNXmCxAn020dolfyyMb8NBmQCZOjZUlyfZt0KFnyMU3I8Fa5ex6Ow8ymGcTRnc/oXrOhclVU7e7tZ+zpe0EibKcsd7vDvW/fXIIkU7DXEMxn5mldf8rq81Zij0YgmebFpHI34dQ4UK1ey7PhIR73tCktUdsUmVX root@zabbix-proxy0496
三、在gitlab上添加ssh-key登錄
github
(二)、經常使用操做
一、把相關的代碼克隆下來緩存
[root@zabbix-proxy0496 gitlab]# git clone git@192.168.4.97:lqb/yw.git Cloning into 'yw'... The authenticity of host '192.168.4.97 (192.168.4.97)' can't be established. ECDSA key fingerprint is SHA256:7OoUZ9xWrE2sHmPq57C3L/DJdhX+zrrYlm58tboarqQ. ECDSA key fingerprint is MD5:fa:38:e5:fc:90:d2:37:47:d4:0f:56:94:2e:8b:44:50. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.4.97' (ECDSA) to the list of known hosts. remote: Enumerating objects: 25, done. remote: Counting objects: 100% (25/25), done. remote: Compressing objects: 100% (20/20), done. remote: Total 25 (delta 6), reused 0 (delta 0) Receiving objects: 100% (25/25), 67.95 KiB | 0 bytes/s, done. Resolving deltas: 100% (6/6), done. [root@zabbix-proxy0496 gitlab]# ls yw
二、進相應的倉庫查看git狀態服務器
[root@zabbix-proxy0496 gitlab]# cd yw/ [root@zabbix-proxy0496 yw]# git status # On branch master nothing to commit, working directory clean [root@zabbix-proxy0496 yw]# ls 1.png CONTRIBUTING.md Dockerfile lqb README.md test.sh
三、建立相應的代碼添加到暫存區並上傳到gitlab服務器上dom
[root@zabbix-proxy0496 yw]# echo "this is first " > index.html [root@zabbix-proxy0496 yw]# cat index.html this is first [root@zabbix-proxy0496 yw]# git add index.html [root@zabbix-proxy0496 yw]# git commit -m 'first commit' [master 7d6a20e] first commit 1 file changed, 1 insertion(+), 1 deletion(-) [root@zabbix-proxy0496 yw]# git push -u origin master Counting objects: 7, done. Delta compression using up to 4 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 519 bytes | 0 bytes/s, done. Total 6 (delta 2), reused 0 (delta 0) To git@192.168.4.97:lqb/yw.git 4497bc1..7d6a20e master -> master Branch master set up to track remote branch master from origin.
四、相關經常使用的命令ssh
[root@zabbix-proxy0496 yw]# git log ###查看歷史提交記錄 [root@zabbix-proxy0496 yw]# git reflog ###查看將來歷史更新點 [root@zabbix-proxy0496 yw]#git reset --hard HEAD ###還原提交版本上一次,上一次提交版本HEAD #########git刪除數據 一、 git rm --cached database #將文件從git暫存區域的追蹤列表移除並不刪除當前工做目錄內的數據文件->只刪除緩存 二、 git rm -f database 4 #將文件數據從git暫存區和工做目錄一塊兒刪除->永久刪除 ##########git重命名數據 三、git mv README NOTICE #### README修改前/NOTICE修改後;最後進行提交git倉庫 2 注意:也可mv修更名稱→刪除git倉庫的文件快照git rm '*.txt'→將新的文件添加進去→提交git倉庫 備註: git rm -f filename #刪除工做區和暫存區的文件 (use --cached to keep the file, or -f to force removal) git diff file #比較本地vs暫存區 git diff --cached file #暫存區vs本地版本庫 git log --oneline # 一行顯示 --decorate # 具體操做 git log -p #顯示詳細信息 git log -1 #顯示1條 commit 至關於作快照 從暫存區恢復到本地工做區 git checkout -- file # 撤銷工做區更改 從版本庫恢復[覆蓋]到暫存區(暫存區錯誤add交) git reset HEAD file 從版本庫回退到版本[某一次commit版本] git reset --hard f34j34 回退後,回退點以後的git log 日誌看不到 git reflog 查看全部commit的日誌
五、標籤使用(通常用於commit以後)ide
[root@zabbix-proxy0496 yw]# git tag v2.0 #####給當前內容打上標籤 [root@zabbix-proxy0496 yw]# git show v2.0 #####查看當前版本v2.0標籤的詳細信息 [root@zabbix-proxy0496 yw]# git tag v2.1 -m "version 2.1 release is test" #######對當前版本(最新)打標記,用於commit提交以後接着進行打標記(-a指定標籤名,-m爲說明信息) [root@zabbix-proxy0496 yw]# git tag #####查看當前全部標籤 v1.0 v2.0 v2.1 [root@zabbix-proxy0496 yw]# git tag -d v2.0 ######刪除標籤v2.0 Deleted tag 'v2.0' (was 1c2bec9) [root@zabbix-proxy0496 yw]# git reset --hard v2.2 HEAD is now at 02318ea this is second [root@zabbix-proxy0496 yw]# git reset --hard 02318ea #######快速回滾 HEAD is now at 02318ea this is second
Workspace:工做區
Index/Stage/Cached:暫存區
Repository:本地倉庫
Remote:遠程倉庫
Git命令就是用於將文件改動切換到不一樣的空間來記錄gitlab
(三)、分支的概念fetch
Git的分支,從本質上來說僅僅是指向提交對象的可變指針。在這一點上與SvN是有着本質的區別。SVN的分支實際上就是一個目錄。
Git的默認分支名字是master。在屢次提交操做以後,你其實已經有一個指向最後那個提交對象的master分支。它會在每次的提交操做中自動向前移動。
git 分支以下圖
經常使用的命令以下:
git branch #查看分支 git checkout dev #切換分支 git merge dev # 合併分支 若是修改了同一個文件,合併時會衝突,須要肯定修改內容 在master 修改衝突的文件,add 提交,commit -->合併完成 git brach -d dev 刪除分支
在實際的項目開發中儘可能保證master分支穩定,僅用於發佈新版本,平時不要直接修改裏面的數據文件。而開發都在dev分支進行修改,即每一個人從dev分支建立本身我的分支,開發完合併到dev分支,最後合併到master分支
一、建立和切換分支
[root@zabbix-proxy0496 yw]# git branch dev #####建立分支 [root@zabbix-proxy0496 yw]# git branch #####查看分支狀況當前分支有*號 dev * master [root@zabbix-proxy0496 yw]# git checkout dev #######切換分支 Switched to branch 'dev' [root@zabbix-proxy0496 yw]# git checkout index.html ######一鍵還原,直接將git倉庫的文件覆蓋當前文件[危險] [root@zabbix-proxy0496 yw]# git branch * dev master
二、合併分支
[root@zabbix-proxy0496 yw]# git checkout master ####切換分支 Switched to branch 'master' [root@zabbix-proxy0496 yw]# git merge dev ####dev分支合併到master Merge made by the 'recursive' strategy. 1.log | 1 + 1 file changed, 1 insertion(+) create mode 100644 1.log [root@zabbix-proxy0496 yw]# git branch dev * master [root@zabbix-proxy0496 yw]# tree . ├── 1.log ├── 1.png ├── CONTRIBUTING.md ├── Dockerfile ├── index.html ├── lqb ├── README.md └── test.sh [root@zabbix-proxy0496 yw]# git branch -d dev ######刪除dev分支 Deleted branch dev (was a9b4292). [root@zabbix-proxy0496 yw]# git branch * master
(四)、Github
Github顧名思義是一個Git版本庫的託管服務,是目前全球最大的軟件倉庫,擁有上百萬的開發者用戶,也是軟件開發和尋找資源的最佳途徑,Github不只能夠託管各類Git版本倉庫,還擁有了更美觀
的Web界面,您的代碼文件能夠被任何人克隆,使得開發者爲開源項貢獻代碼變得更加容易,固然也能夠付費購買私有庫,這樣高性價比的私有庫真的是幫助到了不少團隊和企業。
一、註冊用戶
二、配置ssh-key
三、建立項目
四、克隆項目到本地
五、推送修改到遠程
echo "#git">> README.md git init git add README.md git commit -m "first commit" git remote add origin git@github.com:lewen/git.git git push -u origin master git remote add origin git@github.com:lewen/git.git git push -u origin master ssh-keygen -t rsa 將公鑰添加到 一個公鑰在github只能綁定一次 將遠程的拉下來,合併後,再 push git fetch 將遠程的更新到本地 git merge origin/master 合併遠程的到本地master 先拉,再合併,再推 #####經常使用的命令 1 add #添加文件內容至索引 2 branch #列出、建立或刪除分支 3 checkout #檢出一個分支或路徑到工做區 4 clone #克隆一個版本庫到一個新目錄 5 commit #記錄變動到版本庫 6 init #建立一個空的 Git 版本庫或從新初始化一個已存在的版本庫 7 log #顯示提交日誌 8 merge #合併兩個或更多開發歷史 9 mv #移動或重命名一個文件、目錄或符號連接 10 pull #獲取併合並另外的版本庫或一個本地分支 11 push #更新遠程引用和相關的對象 12 rm #從工做區和索引中刪除文件 13 show #顯示各類類型的對象 14 status #顯示工做區狀態 15 tag #建立、列出、刪除或校驗一個GPG簽名的 tag 對象