码迷,mamicode.com
首页 > 其他好文 > 详细

git

时间:2016-09-07 01:23:13      阅读:835      评论:0      收藏:0      [点我收藏+]

标签:

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]# cat readme.txt     # 查看文件
1 hehe
[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

 

git

标签:

原文地址:http://www.cnblogs.com/sunmmi/p/5847464.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!