[toc]
前言 不管是做为程序猿 还是运维工程师 ,很多人一定都听说过GitHub 。
分布式版本控制系统 版本控制 不管实在企业中,在个人,都接触过版本控制 比如:
什么是分布式 分布式系统是由一组通过网络进行通信、为了完成共同的任务而协调工作的计算机节点组成的系统。分 布式系统的出现是为了用廉价的、普通的2机器完成单个计算机无法完成的计算、存储任务。其目的是利 用更多的机器,处理更多的数据。
因为 Git 是分布式的,所以 Git 支持离线工作,在本地可以进行很多操作,包括接下来将要重磅推出的 分支功能.
git本地仓库 git部署 1 2 3 4 5 yum install -y git git --version
web操作 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 yum install -y nginx server{ listen 80; server_name _; root /code/web; index index.html; } mkdir /code/websystemctl start nginx
使用git管理 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 mkdir webcd webgit init git config --global color.ui auto ll -a total 4 drwxr-xr-x 3 root root 18 May 11 14:47 . dr-xr-x---. 10 root root 4096 May 11 14:45 .. drwxr-xr-x 7 root root 119 May 11 14:47 .git cat .git/config[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true tree -a . └── .git ├── branches ├── config ├── description ├── HEAD ├── hooks │ ├── applypatch-msg.sample │ ├── commit-msg.sample │ ├── post-update.sample │ ├── pre-applypatch.sample │ ├── pre-commit.sample │ ├── prepare-commit-msg.sample │ ├── pre-push.sample │ ├── pre-rebase.sample │ └── update.sample ├── info │ └── exclude ├── objects │ ├── info │ └── pack └── refs ├── heads └── tags 10 directories, 13 files
gitlib本地仓库版本控制并实现需求 需求一 老板:给我写一个官网 程序猿:一天一夜,写出来了,请CEO过目
在仓库中写代码
html代码
1 2 3 4 5 6 7 8 9 10 11 12 13 <!DOCTYPE html> <html lang="zh" > <head > <meta charset="UTF-8" > <meta name="viewport" content="width=device-width, initial-scale=1.0" > <title>代码迭代过程-曾老湿</title> </head> <body> <div id ="demo" ></div> <script src="src.js" ></script> </body> </html>
JS代码
1 2 3 4 5 6 7 8 const string = '老板好,我是程序猿:zls,您让我写的官网页面,它会动' let n = 1demo.innerHTML = string.substring(0,n) setInterval(()=>{ n+=1 demo.innerHTML = string.substring(0 ,n) },200 )
使用git进行版本控制
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 git status nothing added to commit but untracked files present (use "git add" to track) git add . git status
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 git config --global user.email "1944119015@qq.com" git config --global user.name "xxx" git commit -m '源代码v1.0' git log commit 71ba27192e888af354cc2ca33ddd3fb340364b00 Author: Administrator <admin@example.com> Date: Thu May 11 14:55:22 2023 +0800 源代码v1.0 scp /aaa/* 10.0.0.7:/code/web
需求二 老板:不够醒目,再改改 程序猿:好嘞,花了一周时间,请CEO过目
在仓库中写代码
html代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <!DOCTYPE html> <html lang="zh" > <head > <meta charset="UTF-8" > <meta name="viewport" content="width=device-width, initial-scale=1.0" > <style> border: solid 1px red; width: 410px; height: 25px; background-color: lightpink; } </style> <title>代码迭代过程-曾老湿111</title> </head> <body> <div id ="demo" ></div> <script src="src.js" ></script> </body> </html>
JS代码
1 2 3 4 5 6 7 8 const string = '老板好,我是程序猿:zls,您让我写的官网页面,它会动' let n = 1demo.innerHTML = string.substring(0,n) setInterval(()=>{ n+=1 demo.innerHTML = string.substring(0 ,n) },200 )
使用git进行版本控制
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 git status no changes added to commit (use "git add" and/or "git commit -a" ) git add index.html git commit -m '源代码 # 查看日志 git log commit b892777227242a583ff03a09ab09308777b23588 Author: Administrator <admin@example.com> Date: Thu May 11 15:05:57 2023 +0800 源代码v1.1(醒目) commit 71ba27192e888af354cc2ca33ddd3fb340364b00 Author: Administrator <admin@example.com> Date: Thu May 11 14:55:22 2023 +0800 #代码上线 scp ./* 10.0.0.7:/code/web
需求三 老板:还是之前的好看,改回去吧。 程序猿:emmmmmm… 老子不干了。妈的,我该怎么撤回一周内容?
代码回滚
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 git log commit b892777227242a583ff03a09ab09308777b23588 Author: Administrator <admin@example.com> Date: Thu May 11 15:05:57 2023 +0800 源代码v1.1(醒目) commit 71ba27192e888af354cc2ca33ddd3fb340364b00 Author: Administrator <admin@example.com> Date: Thu May 11 14:55:22 2023 +0800 源代码v1.0 git reflog b892777 HEAD@{0}: reset: moving to b892 71ba271 HEAD@{1}: reset: moving to 71ba b892777 HEAD@{2}: commit: 源代码v1.1(醒目) 71ba271 HEAD@{3}: commit (initial): 源代码v1.0 git reset --hard 71ba HEAD is now at 71ba271 源代码v1.0 <!DOCTYPE html> <html lang="zh" > <head > <meta charset="UTF-8" > <meta name="viewport" content="width=device-width, initial-scale=1.0" > <title>代码迭代过程-曾老湿</title> </head> <body> <div id ="demo" ></div> <script src="src.js" ></script> </body> </html> scp ./* 10.0.0.7:/code/web