日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Git实践

發布時間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Git实践 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Git是什么自不必說。Git和gitlab安裝和實踐在后邊的倆篇中會寫。本篇僅重點寫Git自動部署。

Git同樣有Hooks,可以用于各種需求。可以控制提交commit名稱,可以控制代碼規范,也當然包含以下要介紹的自動部署,也不僅包含這些。


Git自動部署簡單的思想是這樣:

  • 在服務端創建空版本庫

  • 在客戶端創建真實版本庫,關聯遠程版本庫

  • 在服務端部署代碼

  • 在服務端版本庫中修改新增鉤子程序




  • 服務端創建空版本庫?

  • ?[yu@argcv-com?~]$?cd?[yu@argcv-com?~]$?mkdir?repo[yu@argcv-com?~]$?cd?repo/[yu@argcv-com?repo]$?git?init?--bare?test.gitInitialized?empty?Git?repository?in?/home/yu/repo/test.git/[yu@argcv-com?repo]$

    2.?在客戶端創建真實版本庫,關聯遠程版本庫

    [yu@argcv-com?~]$?cd?/tmp/ [yu@argcv-com?tmp]$?mkdir?client [yu@argcv-com?tmp]$?cd?client/ [yu@argcv-com?client]$?git?init Initialized?empty?Git?repository?in?/tmp/client/.git/ [yu@argcv-com?client]$?git?remote?add?origin?yu@localhost:repo/test.git [yu@argcv-com?client]$?touch?README.md [yu@argcv-com?client]$?git?add?. [yu@argcv-com?client]$?git?commit?-m?"init" [master?(root-commit)?00da9a9]?init1?file?changed,?0?insertions(+),?0?deletions(-)create?mode?100644?README.md [yu@argcv-com?client]$?git?push?origin?--all? Counting?objects:?3,?done. Writing?objects:?100%?(3/3),?210?bytes,?done. Total?3?(delta?0),?reused?0?(delta?0) To?yu@localhost:repo/test.git*?[new?branch]??????master?->?master [yu@argcv-com?client]$


    3.在服務端部署代碼

    [yu@argcv-com?~]$?cd?/tmp/ [yu@argcv-com?tmp]$?mkdir?deploy [yu@argcv-com?tmp]$?cd?deploy/ [yu@argcv-com?deploy]$?git?clone?~/repo/test.git?. Cloning?into?'.'... done.


    4.在服務端版本庫中修改新增鉤子程序

    [yu@argcv-com?repo]$?pwd /home/yu/repo [yu@argcv-com?repo]$?cd?test.git/ [yu@argcv-com?test.git]$?cd?hooks/ [yu@argcv-com?hooks]$?vi?post-receive [yu@argcv-com?hooks]$?cat?post-receive #!/bin/sh unset?GIT_DIR NowPath=`pwd` echo?"now?path?is?:"$NowPath DeployPath="/tmp/deploy" echo?"deploy?path?is?:"$DeployPath cd?$DeployPath echo?"cd?deploy?path" #git?add?.?-A?&&?git?stash?#?remove?local?changes? git?pull?origin?master?#?pull?data?from?master #?the?follow?line?is?also?ok: #?git?add?.?&&?git?fetch?origin?&&?git?reset?--hard?origin/master echo?"deploy?done" cd?$NowPath echo?"fine" #?---?Finished exit?0 [yu@argcv-com?hooks]$?chmod?+x?post-receive [yu@argcv-com?hooks]$


    5.測試

    [yu@argcv-com?client]$?touch?newfile [yu@argcv-com?client]$?git?add?. [yu@argcv-com?client]$?git?commit?-m?"add?new?file" [master?68efdcf]?add?new?file1?file?changed,?0?insertions(+),?0?deletions(-)create?mode?100644?newfile [yu@argcv-com?client]$?git?push?origin Counting?objects:?4,?done. Delta?compression?using?up?to?2?threads. Compressing?objects:?100%?(2/2),?done. Writing?objects:?100%?(3/3),?384?bytes,?done. Total?3?(delta?0),?reused?0?(delta?0) remote:?now?path?is?:/home/yu/repo/test.git remote:?deploy?path?is?:/tmp/deploy remote:?cd?deploy?path remote:?From?/home/yu/repo/test remote:????6627165..5ac80ec??master?????->?origin/master remote:?Updating?6627165..5ac80ec remote:?Fast-forward remote:??newfile?|?0 remote:??1?file?changed,?0?insertions(+),?0?deletions(-) remote:??create?mode?100644?newfile remote:?deploy?done remote:?fine To?yu@localhost:repo/test.gitb3a32f2..5ac80ec??master?->?master [yu@argcv-com?client]$


    轉載于:https://blog.51cto.com/rhino/1843183

    總結

    以上是生活随笔為你收集整理的Git实践的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。