git 应用

1.git官网

https://www.git-scm.com/

2.git安装

[root@git ~]# yum install git

3.用户配置,初始化环境

[root@git ~]# git config --global user.name "xiaoyi"                  # 创建用户
[root@git ~]# git  config --global user.email "admin@xiaoyi.com"      # 配置邮箱
[root@git ~]# git config --global color.ui true                       # 配置颜色
[root@git ~]# git config --list                       # 查看配置
user.name=xiaoyi
user.email=admin@xiaoyi.com
color.ui=true
[root@git ~]# mkdir xiao         # 创建仓库目录
[root@git ~]# cd xiao/
[root@git xiao]# git init        # 初始化仓库
Initialized empty Git repository in /root/xiao/.git/
[root@git xiao]# ll -a
total 12
drwxr-xr-x. 3 root root 4096 Jun 14 10:06 .
dr-xr-x---. 4 root root 4096 Jun 14 10:06 ..
drwxr-xr-x. 7 root root 4096 Jun 14 10:06 .git

4.创建文件,并提交

[root@git xiao]# echo "1 hehe" > readme.txt   # 创建文件                                                                                                                                                                                                                       
[root@git xiao]# git status         # 查询
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       readme.txt
nothing added to commit but untracked files present (use "git add" to track)
[root@git xiao]# git add readme.txt # 加入到暂存区
[root@git xiao]# git status         # 查询
# On branch master   
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   readme.txt
#
[root@git xiao]# git commit -m "the first commit"  # 提交到仓库
[master (root-commit) 3511675] the first commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 readme.txt

5.提交第二个文件

[root@git xiao]# echo "xiao" > deploy.sh  # 创建文件
[root@git xiao]# git add deploy.sh        # 提交到暂存区
[root@git xiao]# git status               # 查看状态
[root@git xiao]# git commit -m "2th"      # 提交
[root@git xiao]# git log                  # 查看日志

6.修改文件

[root@git xiao]# echo 2 >> deploy.sh    # 追加文件
[root@git xiao]# git status      
[root@git xiao]# git add deploy.sh 
[root@git xiao]# git commit -m "add 2"
[root@git xiao]# git log               # 查看日志
commit cc7913913c2f1d037dab05ee0a5e50b5ec8b9d36
Author: xiaoyi <admin@xiaoyi.com>
Date:   Tue Jun 14 10:30:09 2016 +0800

    add 2

commit c91cad8dbe07c8671c5eed33073d666ea6ce26ad
Author: xiaoyi <admin@xiaoyi.com>
Date:   Tue Jun 14 10:25:09 2016 +0800

    2th

commit 3511675998635b5bbc3e8384cdf3867b57a96d0a
Author: xiaoyi <admin@xiaoyi.com>
Date:   Tue Jun 14 10:13:28 2016 +0800

    the first commit

7.版本回退

[root@git xiao]# cat deploy.sh          # 当前版本内容
xiao
2
[root@git xiao]# git reset --hard HEAD^ # 一个^回退上一个版本,二个^^回退前二个版本
HEAD is now at c91cad8 2th
[root@git xiao]# cat deploy.sh 
xiao

8.回退到指定版本

[root@git xiao]# git reflog            # 查看flog
c91cad8 HEAD@{0}: HEAD^: updating HEAD
cc79139 HEAD@{1}: commit: add 2
c91cad8 HEAD@{2}: commit: 2th
3511675 HEAD@{3}: commit (initial): the first commit
[root@git xiao]# git reset --hard cc79139   # 回退到这个版本

 9.版本迁出

git checkout -- readme.txt

 10.git创建分支与合并

[root@git xiao]# git branch dev     # 创建dev分支
[root@git xiao]# git checkout dev   # 切换到dev分支    【上面2条命令等同于 git checkout -b dev】

[root@git xiao]# ech0 dev > dev.txt # 分支创建文件 [root@git xiao]# git add dev.txt # 加入到暂存区 [root@git xiao]# git commit -m "1st"# 提交
[root@git xiao]# git checkout master# 切换到master [root@git xiao]# git merge dev # 合并dev到master,切记要切换到master [root@git xiao]# ll # 查看合并结果 [root@git xiao]# git branch # 查看当前分支 [root@git xiao]# git branch -d dev # 删除分支 [root@git xiao]# cat dev.txt # 查看冲突的文件

10.推送分支

[root@git xiao]# git push origin dev   # 推送分支
[root@git xiao]# git checkout master   # 切换分支
[root@git xiao]# git branch            # 查看当前分支
[root@git xiao]# git tag v1.0          # 打标记
[root@git xiao]# git tag          # 查看标记 
[root@git xiao]# git show v1.0         # 查看标记
[root@git xiao]# git push origin v1.0  # 推送标记
[root@git xiao]# git checkout v1.0

  

 http://mp.weixin.qq.com/s?__biz=MzIyMDA1MzgyNw==&mid=2651968425&idx=1&sn=3341d98861b20f1abb59c7b032241390&chksm=8c349b85bb431293d44e60ba7d3825c457869c0211dbd0ddb1c25d9e8a0eed8dc28a24596a1f#rd

posted @ 2016-09-06 22:37  sunmmi  阅读(259)  评论(0)    收藏  举报