GIT:
1.下载服务:
root@foundation39 demo]# yum install -y git
- 1
- 2
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
- 1
- 2
- 3
- 4
- 5
- 6
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 ##?? 表示在暂存区
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
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
- 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
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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
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 ##在暂存区内
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
【右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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
【左M】
[root@foundation39 demo]# git add readme.md ##添加到暂存区
[root@foundation39 demo]# git status -s
M readme.md
?? test.txt
- 1
- 2
- 3
- 4
- 5
【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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
当再次添加后,又变为【左M】
[root@foundation39 demo]# git add readme.md
[root@foundation39 demo]# git status -s
M readme.md
?? test.txt
- 1
- 2
- 3
- 4
【A】
[root@foundation39 demo]# git add test.txt
[root@foundation39 demo]# git status -s
M readme.md
A test.txt
- 1
- 2
- 3
- 4
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 ##提交后暂存区里没有东西
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
【回退一层】:
回退前:
[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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
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.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
【配置秘钥】
[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
- 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
【添加密钥】
【查看数据是否同步】
【测试】
[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.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
网页上已经更新:
[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!!