企业级 ##GIT(分布式版本控制系统)##

GIT:
1.下载服务:

root@foundation39 demo]# yum install -y git

2.初始化:

[root@foundation39 ~]# mkdir demo
[root@foundation39 ~]# cd demo/
[root@foundation39 demo]# git init
Initialized empty Git repository in /root/demo/.git/
[root@foundation39 demo]# l.
.  ..  .git

3.建立一个文件,不进行提交,查看状态:

[root@foundation39 demo]# echo westos > readme.md
[root@foundation39 demo]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   readme.md
nothing added to commit but untracked files present (use "git add" to track)
[root@foundation39 demo]# git status -s
?? readme.md                               ##?? 表示在暂存区

4.提交到到版本库后再次查看状态:

[root@foundation39 demo]# git add readme.md
[root@foundation39 demo]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   readme.md
#
[root@foundation39 demo]# git status -s
A  readme.md
[root@foundation39 demo]# git commit -m "add readme.md"        ##提交
[master (root-commit) 3f4eebe] add readme.md               
 Committer: root <root@foundation39.ilt.example.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
 create mode 100644 readme.md

5.上传数据:

[root@foundation39 demo]# git config --global user.name zgd
[root@foundation39 demo]# git config --global user.email "578027311@qq.com"
[root@foundation39 demo]# cd 
[root@foundation39 ~]# cat .gitconfig 
[user]
    name = zgd
    email = 578027311@qq.com

6.状态简览:
这里写图片描述
这里写图片描述

【??】

[root@foundation39 demo]# ls
readme.md
[root@foundation39 demo]# vim test.txt
[root@foundation39 demo]# cat test.txt 
redhat

[root@foundation39 demo]# git status -s
?? test.txt              ##在暂存区内

【右M】

[root@foundation39 demo]# vim readme.md 
[root@foundation39 demo]# cat readme.md 
westos
westos

[root@foundation39 demo]# git status -s
 M readme.md
?? test.txt

【左M】

[root@foundation39 demo]# git add readme.md       ##添加到暂存区
[root@foundation39 demo]# git status -s
M  readme.md
?? test.txt

【MM】 图片里最后一句解释

[root@foundation39 demo]# vim readme.md 
[root@foundation39 demo]# cat readme.md 
westos
westos
westos

[root@foundation39 demo]# git status -s
MM readme.md
?? test.txt

当再次添加后,又变为【左M】

[root@foundation39 demo]# git add readme.md
[root@foundation39 demo]# git status -s
M  readme.md
?? test.txt

【A】

[root@foundation39 demo]# git add test.txt
[root@foundation39 demo]# git status -s
M  readme.md
A  test.txt

7.查看所有执行提交的数据:

[root@foundation39 demo]# git commit -m "add test.txt"     ##提交到版本库
[master 290e05f] add test.txt
 2 files changed, 5 insertions(+)
 create mode 100644 test.txt
[root@foundation39 demo]# git log
commit 290e05f517458c4f9ab86ed06f8fb6b32cfae667
Author: zgd <578027311@qq.com>
Date:   Fri Aug 24 10:00:51 2018 +0800

    add test.txt

commit 3f4eebe3a203b9f4a66d11e26ba5ad6446663f00
Author: root <root@foundation39.ilt.example.com>
Date:   Fri Aug 24 09:44:46 2018 +0800

    add readme.md
[root@foundation39 demo]# git status -s    ##提交后暂存区里没有东西

8.忽略文件:

[root@foundation39 demo]# pwd
/root/demo
[root@foundation39 demo]# ls
readme.md  test.txt
[root@foundation39 demo]# touch .file1
[root@foundation39 demo]# git status -s
?? .file1
[root@foundation39 demo]# cd .git/
[root@foundation39 .git]# ls
branches        config       HEAD   index  logs     refs
COMMIT_EDITMSG  description  hooks  info   objects
[root@foundation39 demo]# vim .gitignore 
[root@foundation39 demo]# cat .gitignore 
.*                       ##忽略所有隐藏文件
[root@foundation39 .git]# cd ..
[root@foundation39 demo]# mv .git/.gitignore .
[root@foundation39 demo]# ls
readme.md  test.txt
[root@foundation39 demo]# l.
.  ..  .file1  .git  .gitignore
[root@foundation39 demo]# git status -s

9.版本回退:

[root@foundation39 demo]# pwd
/root/demo
[root@foundation39 demo]# ls
readme.md  test.txt
[root@foundation39 demo]# git log --pretty=oneline
290e05f517458c4f9ab86ed06f8fb6b32cfae667 add test.txt
3f4eebe3a203b9f4a66d11e26ba5ad6446663f00 add readme.md
[root@foundation39 demo]# git log
commit 290e05f517458c4f9ab86ed06f8fb6b32cfae667
Author: zgd <578027311@qq.com>
Date:   Fri Aug 24 10:00:51 2018 +0800

    add test.txt

commit 3f4eebe3a203b9f4a66d11e26ba5ad6446663f00
Author: root <root@foundation39.ilt.example.com>
Date:   Fri Aug 24 09:44:46 2018 +0800

    add readme.md

【回退一层】:

回退前:
[root@foundation39 demo]# vim readme.md 
[root@foundation39 demo]# cat readme.md 
westos
westos
回退后:
[root@foundation39 demo]# git reset --hard HEAD^   ##^代表回退一层
HEAD is now at 3f4eebe add readme.md
[root@foundation39 demo]# git status -s
[root@foundation39 demo]# ls
readme.md
[root@foundation39 demo]# cat readme.md 
westos

10.git网页使用:
【注册帐号】
这里写图片描述
【登陆】
这里写图片描述
【添加project】
这里写图片描述
这里写图片描述
【数据同步】

[root@foundation39 demo]# git remote add origin https://github.com/zgdsssd/westos.git
[root@foundation39 demo]# git push -u origin master
Username for 'https://github.com': zgdsssd
Password for 'https://zgdsssd@github.com': 
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (7/7), 486 bytes | 0 bytes/s, done.
Total 7 (delta 0), reused 0 (delta 0)
To https://github.com/zgdsssd/westos.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

【配置秘钥】

[root@foundation39 ~]# cd .ssh/
[root@foundation39 .ssh]# ls
authorized_keys  known_hosts
[root@foundation39 .ssh]# ls
authorized_keys  known_hosts
[root@foundation39 .ssh]# 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:
99:28:9d:01:38:78:d2:8d:83:60:65:96:03:7e:20:9d root@foundation39.ilt.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|+OoOo            |
|B Eo..           |
| + +. .          |
|  .  . + o       |
|    . + S        |
|     .           |
|                 |
|                 |
|                 |
+-----------------+
[root@foundation39 .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[root@foundation39 .ssh]# cat id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDarDVQsGvPnO+w8m1ae10R8m1BP34Lxj087FGFFAxDpl1OgLOLTVK2wpb9h1GHQdblRnlw1TzvHoQ1KtIlNQd+GruNJrB2Mb2ARDamPDbz/RlkCvws6JceEE3F8m52P9ZM3SNO/eiM2NnTtgOWOFiKCnjqx835JBXP7E3wsZqQxCu06/ZOLGlQdZvzteJxEIswuEuYLoE9Qhco//uswS3qldx2sq320wpl/1ui0vxlMsXAXXU680pUCC4dhZ7gDnGlK5Gmjw0IkMSAoDQVUGzkx2IpHFyaK8Zuj10nPX+B/dKnVZ3D7Ppz5g5q00y9h3IE6vJ4MD52xT4VZl9xNP7B root@foundation39.ilt.example.com

【添加密钥】
这里写图片描述
这里写图片描述
【查看数据是否同步】
这里写图片描述
【测试】
[1]在shell添加数据,在网页查看是否同步

[root@foundation39 demo]# vim test.txt 
[root@foundation39 demo]# cat test.txt 
redhat
redhat
zgd123456

[root@foundation39 demo]# git add test.txt
[root@foundation39 demo]# git commit -m "add test.txt"
[master d4d2834] add test.txt
 1 file changed, 2 insertions(+)
[root@foundation39 demo]# git push -u origin master 
Username for 'https://github.com': zgdsssd
Password for 'https://zgdsssd@github.com': 
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 288 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/zgdsssd/westos.git
   290e05f..d4d2834  master -> master
Branch master set up to track remote branch master from origin.

网页上已经更新:
这里写图片描述
[2]在网页上添加数据,在shell中查看是否同步
这里写图片描述
这里写图片描述
shell上已经更新:

[root@foundation39 demo]# git remote  -v
origin  https://github.com/zgdsssd/westos.git (fetch)
origin  https://github.com/zgdsssd/westos.git (push)
[root@foundation39 demo]# git fetch -u origin master:master 
HEAD:HEAD       master:master   
[root@foundation39 demo]# git fetch -u origin master
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/zgdsssd/westos
 * branch            master     -> FETCH_HEAD
[root@foundation39 demo]# git pull origin 
From https://github.com/zgdsssd/westos
   d4d2834..6805d4f  master     -> origin/master
Updating d4d2834..6805d4f
Fast-forward
 test.txt | 3 +++
 1 file changed, 3 insertions(+)
[root@foundation39 demo]# ls
readme.md  test.txt
[root@foundation39 demo]# cat test.txt 
redhat
redhat
zgd123456
hello james
hello westbrook!!
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值