永久修改主機名 vim /etc/hostname devops應用 開發寫完代碼上傳到git或者Gitlab,Jenkins從gitlab拉去代碼,(叫持續集成ci) maven就是java的yum倉庫 分佈式集成了本地倉庫和遠程倉庫的合成。 先上傳到本地倉庫,而後在吧本地倉庫推到遠程倉庫。即便沒有遠程倉庫。兩個本地倉庫以能夠互推。 公有遠程倉庫的網址 https://github.com 能夠註冊本身的遠程倉庫。
編譯安裝過程 yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel yum -y install gcc perl-ExtUtils-MakeMaker tar xf git-2.9.5.tar.gz -C /usr/src/ cd /usr/src/git-2.9.5/ ./configure --prefix=/usr/local/git make && make install ln -sf /usr/local/git/bin/* /usr/bin/ ln -s /usr/libexec/git-core/* /usr/bin/ 全局變量開啓中文 export LANG=zh_CN.UTF8 初始git目錄 mkdir -p /mycode cd /mycode [root@git1 mycode]# git init 初始化空的 Git 倉庫於 /mycode/.git/ 建立一個暫時緩存 [root@git mycode]# touch test.txt 提交到暫存區 [root@git mycode]# git add *(刪除的暫存提交git rm 文件名) [root@git mycode]# git status 位於分支 master 初始提交 要提交的變動: (使用 "git rm --cached <文件>..." 以取消暫存) 新文件: test.txt git commit 將暫存提交到本地倉庫 必須-m寫說明,要不不讓提交 [root@git mycode]# git commit -m "test" *** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got 'root@git.(none)') 還須要作全局變量,告訴他是誰,還有郵箱 而後提交成功 [root@git mycode]# git config --global user.email "491537692@qq.com" [root@git mycode]# git config --global user.name "cashsunan" [root@git mycode]# git commit -m "test" [master(根提交) cc12e4d] test 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test.txt [root@git mycode]# 查看遠程倉庫 [root@git mycode]# git remote -v 添加到遠程倉庫 git remote add 代號 url 默認的代號叫origin [root@git mycode]# git remote add test https://github.com/cashsunan/sunan.git 將文件推到遠程倉庫 git push -u 代號(給倉庫設置的代號)master(要推到那個分支) 推送 標籤 git push -u 代號 標籤 [root@git mycode]# git push -u test master Username for 'https://github.com': 491537692@qq.com Password for 'https://491537692@qq.com@github.com': 對象計數中: 3, 完成. 寫入對象中: 100% (3/3), 200 bytes | 0 bytes/s, 完成. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/cashsunan/sunan.git * [new branch] master -> master 分支 master 設置爲跟蹤來自 test 的遠程分支 master。
要到另外一個服務器上實驗 [root@git1 mycode]# git clone https://github.com/cashsunan/sunan.git master 正克隆到 'master'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 展開對象中: 100% (3/3), 完成. 檢查鏈接... 完成。 [root@git1 mycode]# ls master [root@git1 mycode]# cd master/ [root@git1 master]# ls test.txt [root@git1 master]# git status 位於分支 master 您的分支與上游分支 'origin/master' 一致。 nothing to commit, working tree clean [root@git1 master]# echo "xxx" >> test.txt [root@git1 master]# touch exe.txt [root@git1 master]# git status 位於分支 master 您的分支與上游分支 'origin/master' 一致。 還沒有暫存以備提交的變動: (使用 "git add <文件>..." 更新要提交的內容) (使用 "git checkout -- <文件>..." 丟棄工做區的改動) 修改: test.txt 修改還沒有加入提交(使用 "git add" 和/或 "git commit -a" 再次提交 [root@git1 master]# git add * [root@git1 master]# git commit -m "wo cao " 位於分支 master 您的分支與上游分支 'origin/master' 一致。 還沒有暫存以備提交的變動: 修改: test.txt 修改還沒有加入提交 [root@git1 master]# git remote -v origin https://github.com/cashsunan/sunan.git (fetch) origin https://github.com/cashsunan/sunan.git (push) [root@git1 master]# git push -u origin master Username for 'https://github.com': 491537692@qq.com Password for 'https://491537692@qq.com@github.com': 對象計數中: 3, 完成. 壓縮對象中: 100% (2/2), 完成. 寫入對象中: 100% (3/3), 277 bytes | 0 bytes/s, 完成. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/cashsunan/sunan.git cc12e4d..5535cc9 master -> master 分支 master 設置爲跟蹤來自 origin 的遠程分支 master。
在git上實驗 [root@git mycode]# git remote -v test https://github.com/cashsunan/sunan.git (fetch) test https://github.com/cashsunan/sunan.git (push) [root@git mycode]# git fetch -u test master 來自 https://github.com/cashsunan/sunan * branch master -> FETCH_HEAD [root@git mycode]# git status 位於分支 master 您的分支落後 'test/master' 共 1 個提交,而且能夠快進。 (使用 "git pull" 來更新您的本地分支) nothing to commit, working tree clean [root@git mycode]# git checkout 您的分支落後 'test/master' 共 1 個提交,而且能夠快進。 (使用 "git pull" 來更新您的本地分支) 將遠程倉庫的變動合併到本地 [root@git mycode]# git merge test/master 更新 cc12e4d..5535cc9 Fast-forward exe.txt | 0 test.txt | 3 +++ 2 files changed, 3 insertions(+) create mode 100644 exe.txt 將遠程的倉庫一步到位的更新到本地, 先在git服務器提交新的變化 [root@git mycode]# echo "adfasdf" >> exe.txt [root@git mycode]# git add * [root@git mycode]# git commit -m "2ci" [master e770d42] 2ci 1 file changed, 1 insertion(+) [root@git mycode]# git push -u test master Username for 'https://github.com': 491537692@qq.com Password for 'https://491537692@qq.com@github.com': 對象計數中: 3, 完成. 壓縮對象中: 100% (2/2), 完成. 寫入對象中: 100% (3/3), 266 bytes | 0 bytes/s, 完成. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/cashsunan/sunan.git 5535cc9..e770d42 master -> master 分支 master 設置爲跟蹤來自 test 的遠程分支 master 提交完成後在git1上直接pull拉取 [root@git1 master]# git pull origin master remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 展開對象中: 100% (3/3), 完成. 來自 https://github.com/cashsunan/sunan * branch master -> FETCH_HEAD 5535cc9..e770d42 master -> origin/master 更新 5535cc9..e770d42 Fast-forward exe.txt | 1 + 1 file changed, 1 insertion(+)
git命令在本地倉庫和暫存區的命令 文件的更名: git mv xxx yyy 撤銷命令 :git reset 文件名 本地倉庫文件和修改的工做區文件進行對比 :git diff 文件名 (-是刪除+添加) 查看git的本地歷史提交記錄:git log git log的參數 :git log -2 最近2次提交的 git log -p -1 顯示每次提交的內容差別 git log --stat -2 :stat簡要顯示數據的增改行數,這樣就能看到提交中修改過的內容 git log --pretty=oneline:一行顯示提交的歷史記錄 本地回到上一個版本的命令 git reset --hard HEAD^ 回滾到指定版本,git reset --hard 歷史記錄的編碼號 回滾錯了回覆, git reflog : 查看歷史的更新點. 裏邊有編碼號,查到了編碼號之間回滾 git reset --hard 歷史記錄的編碼號 建立版本號 git tag 版本號 [root@git1 master]# git tag v1.0 [root@git1 master]# git tag v1.0 查看版本的標籤狀態 [root@git1 master]# git show v1.0 commit e770d42ad78a3f2a6892bd6ee39a2a78e5a6a119 Author: cashsunan <491537692@qq.com> Date: Sun Dec 16 17:31:19 2018 +0800 2ci diff --git a/exe.txt b/exe.txt index e69de29..25975e2 100644 --- a/exe.txt +++ b/exe.txt @@ -0,0 +1 @@ 刪除標籤 [root@git1 master]# git tag -d v1.0 用標籤回滾 [root@git1 master]# git reset --hard v2.0 HEAD 如今位於 e770d42 2ci 已刪除標籤 'v1.0'(曾爲 e770d42) 建立分支 git branch xx 查看分支 git branch 刪除分支 git branch -d xx 強刪分支 git branch -D xx 切換分支 git checkout xx 檢查本地分支和遠程分支是否相同 git checkout 暫存區是公用的,在工做以前要不就狀況,要不就提交 合併分支 自動合併 在主支上 git merge 想要合併的分支 [root@git1 master]# git merge dev 更新 e770d42..ae291fe Fast-forward 1.txt | 0 quit | 12 ++++++++++++ test.txt | 1 + 3 files changed, 13 insertions(+) create mode 100644 1.txt create mode 100644 quit [root@git1 master]# git branch dev * master [root@git1 master]# git push -u origin master Username for 'https://github.com': 491537692@qq.com Password for 'https://491537692@qq.com@github.com': Total 0 (delta 0), reused 0 (delta 0) To https://github.com/cashsunan/sunan.git e770d42..ae291fe master -> master 分支 master 設置爲跟蹤來自 origin 的遠程分支 master。 [root@git1 master]# git status 位於分支 master 您的分支與上游分支 'origin/master' 一致
gitignore文本忽略文件, 會建立以個隱藏的文件.gitingnore 寫法 target *.logt 表示忽略項目中全部以.log結尾的文件 ?.idea表示忽略一個字符以.idea結尾的文件 /errt.log忽略根目錄下的error.log文件 **/java/匹配全部java目錄下的全部文件 !/error.log表示在前面的匹配規則中,被忽略的文件,不想被忽略,就加!