IT环境部署 && 自动化
操作系统安装 COBBLER
服务部署 SALTSTACK
应用代码部署 saltstack && shell
监控配置 zabbix
加入运维集群 LVS && haproxy
安装部署git
[root@linux-node2 ~]# yum install git -y
设置本地的用户名和邮箱
[root@linux-node2 ~]# git config --global user.name "chenjisong"
[root@linux-node2 ~]# git config --global user.email "406564728@qq.com"
[root@linux-node2 ~]# git config --global color.ui true
[root@linux-node2 ~]# git config --list
user.name=chenjisong
user.email=406564728@qq.com
color.ui=true
创建一个版本库:
[root@linux-node2 ~]# mkdir oldboy
[root@linux-node2 ~]# cd oldboy/
[root@linux-node2 oldboy]# git init
Initialized empty Git repository in /root/oldboy/.git/
[root@linux-node2 oldboy]# echo "1 hehe" > readme.txt
[root@linux-node2 oldboy]# cat readme.txt
1 hehe
[root@linux-node2 oldboy]# git add readme.txt ---添加至版本库
[root@linux-node2 oldboy]# git commit -m "the first commit" ---提交
[root@linux-node2 oldboy]# cat deploy.sh
#!/bin/bash
echo hehe
[root@linux-node2 oldboy]# git add deploy.sh
[root@linux-node2 oldboy]# git commit -m "2th commit"
[root@linux-node2 oldboy]# git log -----查看提交记录
[root@linux-node2 oldboy]# cat readme.txt -----加了一行
1 hehe
2 haha
[root@linux-node2 oldboy]# git status 再次查看状态,提示文件改变了
[root@linux-node2 oldboy]# git diff readme.txt git diff对比两次文件修改之处
diff --git a/readme.txt b/readme.txt
index 408e625..5293fff 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1 +1,2 @@
1 hehe
+2 haha
[root@linux-node2 oldboy]# git add readme.txt
[root@linux-node2 oldboy]# git commit -m "add 2haha"
[master f951bc2] add 2haha
1 files changed, 1 insertions(+), 0 deletions(-)
[root@linux-node2 oldboy]# git log ----查看提交记录
commit f951bc28b0d2c55d320983c76bcd0523f2101973
Author: chenjisong <406564728@qq.com>
Date: Fri Nov 27 14:23:02 2015 +0800
add 2haha
commit 44c16df44ab14f8769569bd31cc586256f579911
Author: chenjisong <406564728@qq.com>
Date: Fri Nov 27 14:18:38 2015 +0800
2th commit
commit fea2e2d32e1684523684c6acd83ba0dfdc3b4d56
Author: chenjisong <406564728@qq.com>
Date: Fri Nov 27 14:16:12 2015 +0800
the first commit
[root@linux-node2 oldboy]# git reset --hard HEAD^ git reset版本回退命令 HEAD^表示上一版本
HEAD is now at 44c16df 2th commit
[root@linux-node2 oldboy]# git reflog git reflog列出每一个版本
44c16df HEAD@{0}: HEAD^: updating HEAD
f951bc2 HEAD@{1}: commit: add 2haha
44c16df HEAD@{2}: commit: 2th commit
fea2e2d HEAD@{3}: commit (initial): the first commit
[root@linux-node2 oldboy]# git reset --hard fea2e2d 后面直接接回退的版本则OK
HEAD is now at fea2e2d the first commit
[root@linux-node2 oldboy]# ll ---此处没有deploy.sh文件了
总用量 4
-rw-r--r-- 1 root root 7 11月 27 14:26 readme.txt
[root@linux-node2 oldboy]# cat readme.txt
1 hehe
总结:
1 git add readme.txt git add加入到暂存区
2 git commit -m "add 2haha" git commit 提交到工作区
3 git log git log 查看提交日志
4 git reset --hard HRAD^ git reset回退版本
5 git reflog git reflog查看历史提交记录
6 git reset --hard fea2e2d git reset根据commit id来回退版本
####################################################################################################
[root@linux-node2 oldboy]# cat readme.txt
1 hehe
2 wo shi hehe ---新加的一行
[root@linux-node2 oldboy]# git commit -m "add 2"
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: readme.txt
#
no changes added to commit (use "git add" and/or "git commit -a") 没有任何的改变去提交
注意:必须先提交到暂存区,然后才能提交到工作区
[root@linux-node2 oldboy]# git add readme.txt ----先提交到暂存区
[root@linux-node2 oldboy]# git commit -m "add 2" ----提交到工作区才能成功
[master 0125b6d] add 2
1 files changed, 1 insertions(+), 0 deletions(-)
[root@linux-node2 oldboy]# cat readme.txt
1 hehe
2 wo shi hehe
3 hehe hehe ---新加的一行
[root@linux-node2 oldboy]# vim readme.txt
1 hehe
2 wo shi hehe
3 hehe hehe
4 haha 新加的一行
[root@linux-node2 oldboy]# git checkout readme.txt -git checkout,对刚修改,暂未提交的文件回退
[root@linux-node2 oldboy]# cat readme.txt
1 hehe
2 wo shi hehe
3 hehe hehe
远程仓库:
[root@linux-node2 oldboy]# git remote add origin git@github.com:chenjisong/test.git
-----添加至远程版本库
[root@linux-node2 oldboy]# cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@github.com:chenjisong/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
73 git push -u origin master
74 git pull
75 git pull origin master ----先pull下来
76 ls -a
77 git push -u origin master ----然后再push上去
[root@linux-node2 tmp]# git clone git@github.com:chenjisong/test.git 远端克隆别人的东西
Initialized empty Git repository in /tmp/test/.git/
remote: Counting objects: 16, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 16 (delta 1), reused 12 (delta 1), pack-reused 0
Receiving objects: 100% (16/16), 5.43 KiB, done.
Resolving deltas: 100% (1/1), done.
branch管理
[root@linux-node2 oldboy]# git branch dev
[root@linux-node2 oldboy]# git checkout dev
Switched to branch ‘dev‘
[root@linux-node2 oldboy]# git branch
* dev
master
合并分支:如果要将dev与master进行合并,首先切换到master分支
[root@linux-node2 oldboy]# git checkout master
Switched to branch ‘master‘
[root@linux-node2 oldboy]# git merge dev
Updating 5dfef63..ae15e52
Fast-forward
dev.txt | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 dev.txt
[root@linux-node2 oldboy]# ll
总用量 24
-rw-r--r-- 1 root root 13 11月 27 15:31 dev.txt -----dev分支的内容,已合并
-rw-r--r-- 1 root root 11358 11月 27 15:10 LICENSE
-rw-r--r-- 1 root root 12 11月 27 15:10 README.md
-rw-r--r-- 1 root root 33 11月 27 14:49 readme.txt
[root@linux-node2 oldboy]# git branch
dev
* master
[root@linux-node2 oldboy]# git branch -d dev -d 删除分支
[root@linux-node2 oldboy]# git checkout -b test -b 创建分支
[root@linux-node2 oldboy]# git tag v1.0 git tag 打标签
[root@linux-node2 oldboy]# git tag
v1.0
本文出自 “linux” 博客,请务必保留此出处http://chenjisong.blog.51cto.com/7858025/1726299
原文地址:http://chenjisong.blog.51cto.com/7858025/1726299