git基本操作

git基本操作

环境

iphostnamesoftOS
192.168.48.56webgitCentOs7.6

安装git

[root@web ~]# wget https://github.com/git/git/archive/v2.23.0.tar.gz
[root@web ~]# tar xvf v2.23.0.tar.gz
[root@web ~]# cd V2.23.0/
[root@web git-2.23.0]# make configure
[root@web git-2.23.0]# ./configure --prefix=/usr
[root@web git-2.23.0]# make all doc info 
[root@web git-2.23.0]# make install install-doc install-html install-info
[root@web ~]# git --version 
git version 2.23.0

配置user

[root@web ~]# git config --global user.name 'tk8s'
[root@web ~]# git config --global user.email 'tk8s@tk8s.com'
[root@web ~]# git config --list --global 
user.name=tk8s
user.email=tk8s@tk8s.com

config

git config --local local只对某个仓库有效
git config --global global对当前所有仓库有效
git config --system system对系统所有登录的用户有效
显示config的配置,--list
git config --list --local 
git config --list --global 
git config --list --system

建立git仓库

1.把已有的项目代码纳入git管理
cd 项目代码所在的文件夹
git init
2.新建项目直接用git管理
git init 项目代码文件夹
cd 项目代码文件夹
[root@web ~]# git init git_test
Initialized empty Git repository in /root/git_test/.git/
[root@web ~]# cd git_test/
[root@web git_test]# ll -a
total 0
drwxr-xr-x  3 root root  18 Aug 26 13:31 .
dr-xr-x---. 7 root root 249 Aug 26 13:31 ..
drwxr-xr-x  7 root root 119 Aug 26 13:31 .git

git仓库添加文件,提交文件

[root@web git_test]# echo “test” > README
[root@web git_test]# git add README
[root@web git_test]# git status 
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   README
#

[root@web git_test]# git commit -m "add readme"
[master (root-commit) 7e56f12] add readme
 1 file changed, 1 insertion(+)
 create mode 100644 README
[root@web git_test]# git log 
commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme

暂存区

  • 第一步是用git add把文件添加进去,实际上就是把文件修改添加到暂存区;
  • 第二步是用git commit提交更改,实际上就是把暂存区的所有内容提交到当前分支。
[root@web git_test]# echo "test1" > index1.html
[root@web git_test]# echo "test2" > index2.html
[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root  6 Aug 26 13:44 index1.html
-rw-r--r-- 1 root root  6 Aug 26 13:44 index2.html
-rw-r--r-- 1 root root 11 Aug 26 13:35 README
[root@web git_test]# git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	index1.html
#	index2.html
nothing added to commit but untracked files present (use "git add" to track)

[root@web git_test]# git add index1.html index2.html
[root@web git_test]# git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	new file:   index1.html
#	new file:   index2.html
#
[root@web git_test]# git commit -m "add index"
[master 248abb7] add index
 2 files changed, 2 insertions(+)
 create mode 100644 index1.html
 create mode 100644 index2.html
[root@web git_test]# git log
commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index

commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme

修改存在的文件

[root@web git_test]# echo "test1,ok" > index1.html 
[root@web git_test]# git status 
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   index1.html
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@web git_test]# git add -u 
[root@web git_test]# git status 
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   index1.html
#

[root@web git_test]# git commit -m "modify index1.html"
[master 4712391] modify index1.html
 1 file changed, 1 insertion(+), 1 deletion(-)
[root@web git_test]# git log 
commit 4712391e40f6a886542693af3ba4208b6a997701
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify index1.html

commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index

commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme

rename文件名

[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root  9 Aug 26 13:52 index1.html
-rw-r--r-- 1 root root  6 Aug 26 13:44 index2.html
-rw-r--r-- 1 root root 11 Aug 26 13:35 README
[root@web git_test]# git mv  README README.md
[root@web git_test]# git status 
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	renamed:    README -> README.md
#
[root@web git_test]# git commit -m "move readme to readme.md"
[master 2fb91d6] move readme to readme.md
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename README => README.md (100%)
[root@web git_test]# git log
commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move readme to readme.md

commit 4712391e40f6a886542693af3ba4208b6a997701
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify index1.html

commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index

commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme

日志

[root@web git_test]# git log
commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move readme to readme.md

commit 4712391e40f6a886542693af3ba4208b6a997701
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify index1.html

commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index

commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme

[root@web git_test]# git log --oneline 
2fb91d6 move readme to readme.md
4712391 modify index1.html
248abb7 add index
7e56f12 add readme

[root@web git_test]# git log -n2
commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move readme to readme.md

commit 4712391e40f6a886542693af3ba4208b6a997701
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify index1.html
[root@web git_test]# git log -n3
commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move readme to readme.md

commit 4712391e40f6a886542693af3ba4208b6a997701
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify index1.html

commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index
[root@web git_test]# git log -n4
commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move readme to readme.md

commit 4712391e40f6a886542693af3ba4208b6a997701
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify index1.html

commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index

commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme

[root@web git_test]# git log --oneline  -n1
2fb91d6 move readme to readme.md
[root@web git_test]# git log --oneline  -n2
2fb91d6 move readme to readme.md
4712391 modify index1.html
[root@web git_test]# git log --oneline  -n3
2fb91d6 move readme to readme.md
4712391 modify index1.html
248abb7 add index
[root@web git_test]# git log --graph 
* commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 14:22:27 2019 +0800
| 
|     move readme to readme.md
|  
* commit 4712391e40f6a886542693af3ba4208b6a997701
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 13:54:46 2019 +0800
| 
|     modify index1.html
|  
* commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 13:50:43 2019 +0800
| 
|     add index
|  
* commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
  Author: tk8s <tk8s@tk8s.com>
  Date:   Mon Aug 26 13:35:52 2019 +0800
  
      add readme

分支

[root@web git_test]# git branch -v
* master 2fb91d6 move readme to readme.md
[root@web git_test]# git branch --list
* master

[root@web git_test]# git checkout -b dev
Switched to a new branch 'dev'
[root@web git_test]# git branch --list
* dev
  master
[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root  9 Aug 26 13:52 index1.html
-rw-r--r-- 1 root root  6 Aug 26 13:44 index2.html
-rw-r--r-- 1 root root 11 Aug 26 13:35 README.md
[root@web git_test]# git log
commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move readme to readme.md

commit 4712391e40f6a886542693af3ba4208b6a997701
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify index1.html

commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index

commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme

[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root  9 Aug 26 13:52 index1.html
-rw-r--r-- 1 root root  6 Aug 26 13:44 index2.html
-rw-r--r-- 1 root root 11 Aug 26 13:35 README.md
[root@web git_test]# echo "dev" > README.md 
[root@web git_test]# git add README.md
[root@web git_test]# git commit -m "dev"
[dev b82e5ce] dev
 1 file changed, 1 insertion(+), 1 deletion(-)
[root@web git_test]# git log 
commit b82e5ce65db9682c90e4984cc344763dade4dc61
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 15:14:11 2019 +0800

    dev

commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move readme to readme.md

commit 4712391e40f6a886542693af3ba4208b6a997701
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify index1.html

commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index

commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme

[root@web git_test]# git log --all --graph 
* commit b82e5ce65db9682c90e4984cc344763dade4dc61 (dev)
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 15:14:11 2019 +0800
| 
|     dev
| 
* commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e (HEAD -> master)
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 14:22:27 2019 +0800
| 
|     move readme to readme.md
| 
* commit 4712391e40f6a886542693af3ba4208b6a997701
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 13:54:46 2019 +0800
| 
|     modify index1.html
| 
* commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 13:50:43 2019 +0800
| 
|     add index
| 
* commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
  Author: tk8s <tk8s@tk8s.com>
  Date:   Mon Aug 26 13:35:52 2019 +0800
  
      add readme

.git

[root@web git_test]# ll -a
total 16
drwxr-xr-x  3 root root   73 Aug 26 15:16 .
dr-xr-x---. 8 root root 4096 Aug 26 15:44 ..
drwxr-xr-x  8 root root  166 Aug 26 15:16 .git
-rw-r--r--  1 root root    9 Aug 26 13:52 index1.html
-rw-r--r--  1 root root    6 Aug 26 13:44 index2.html
-rw-r--r--  1 root root   11 Aug 26 15:16 README.md
[root@web git_test]# cd .git/
[root@web .git]# ll
total 20
drwxr-xr-x  2 root root   6 Aug 26 13:31 branches
-rw-r--r--  1 root root   4 Aug 26 15:14 COMMIT_EDITMSG
-rw-r--r--  1 root root  92 Aug 26 13:31 config
-rw-r--r--  1 root root  73 Aug 26 13:31 description
-rw-r--r--  1 root root  23 Aug 26 15:16 HEAD
drwxr-xr-x  2 root root 242 Aug 26 13:31 hooks
-rw-r--r--  1 root root 264 Aug 26 15:16 index
drwxr-xr-x  2 root root  21 Aug 26 13:31 info
drwxr-xr-x  3 root root  30 Aug 26 13:35 logs
drwxr-xr-x 18 root root 170 Aug 26 15:14 objects
drwxr-xr-x  4 root root  31 Aug 26 13:31 refs
[root@web .git]# cat HEAD 
ref: refs/heads/master
[root@web .git]# cat config 
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[root@web .git]# cat refs/heads/master 
2fb91d6cd462e10a1fdc70e4ab364539cc2a459e

[root@web .git]# git cat-file -t 2fb91d6
commit

[root@web .git]# git branch -av
  dev    b82e5ce dev
* master 2fb91d6 move readme to readme.md

[root@web .git]# cd objects/
[root@web objects]# ll
total 0
drwxr-xr-x 2 root root 52 Aug 26 13:35 05
drwxr-xr-x 2 root root 98 Aug 26 14:22 18
drwxr-xr-x 2 root root 52 Aug 26 13:50 24
drwxr-xr-x 2 root root 52 Aug 26 13:50 2d
drwxr-xr-x 2 root root 52 Aug 26 14:22 2f
drwxr-xr-x 2 root root 52 Aug 26 15:13 38
drwxr-xr-x 2 root root 52 Aug 26 13:54 47
drwxr-xr-x 2 root root 52 Aug 26 13:54 52
drwxr-xr-x 2 root root 52 Aug 26 13:35 7e
drwxr-xr-x 2 root root 52 Aug 26 13:45 a5
drwxr-xr-x 2 root root 52 Aug 26 13:53 a8
drwxr-xr-x 2 root root 52 Aug 26 15:14 b8
drwxr-xr-x 2 root root 52 Aug 26 13:35 bd
drwxr-xr-x 2 root root 52 Aug 26 15:14 c9
drwxr-xr-x 2 root root  6 Aug 26 13:31 info
drwxr-xr-x 2 root root  6 Aug 26 13:31 pack
[root@web objects]# cd a5
[root@web a5]# ll
total 4
-r--r--r-- 1 root root 21 Aug 26 13:45 bce3fd2565d8f458555a0c6f42d0504a848bd5
[root@web a5]# git cat-file -t a5bce3fd2565d8f458555a0c6f42d0504a848bd5
blob

[root@web a5]# git cat-file -p a5bce3fd2565d8f458555a0c6f42d0504a848bd5
test1

commit,tree,blob

在这里插入图片描述

[root@web git_test]# git log
commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move readme to readme.md

commit 4712391e40f6a886542693af3ba4208b6a997701
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify index1.html

commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index

commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme

[root@web git_test]# git cat-file -t 2fb91d6cd4
commit

[root@web git_test]# git cat-file -p 2fb91d6cd4
tree 1817efe7bdd73768e2245ef324ae467d83a6b95d
parent 4712391e40f6a886542693af3ba4208b6a997701
author tk8s <tk8s@tk8s.com> 1566800547 +0800
committer tk8s <tk8s@tk8s.com> 1566800547 +0800

move readme to readme.md

[root@web git_test]# git cat-file -p 1817efe7b
100644 blob bd721793c916757eb17ffc248799ad00f0b35735	README.md
100644 blob a851fb8e7b81b65e70d57cd196c21492efdc4fd2	index1.html
100644 blob 180cf8328022becee9aaa2577a8f84ea2b9f3827	index2.html

[root@web git_test]# git cat-file -p bd721793c91
“test”

HEAD,branch

[root@web git_test]# git log --all --graph 
* commit b82e5ce65db9682c90e4984cc344763dade4dc61 (dev)
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 15:14:11 2019 +0800
| 
|     dev
| 
* commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e (HEAD -> master)
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 14:22:27 2019 +0800
| 
|     move readme to readme.md
| 
* commit 4712391e40f6a886542693af3ba4208b6a997701
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 13:54:46 2019 +0800
| 
|     modify index1.html
| 
* commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 13:50:43 2019 +0800
| 
|     add index
| 
* commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
  Author: tk8s <tk8s@tk8s.com>
  Date:   Mon Aug 26 13:35:52 2019 +0800
  
      add readme

[root@web git_test]# git checkout -b readme 7e56f124868
Switched to a new branch 'readme'
[root@web git_test]# git log --all --graph 
* commit b82e5ce65db9682c90e4984cc344763dade4dc61 (dev)
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 15:14:11 2019 +0800
| 
|     dev
| 
* commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e (master)
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 14:22:27 2019 +0800
| 
|     move readme to readme.md
| 
* commit 4712391e40f6a886542693af3ba4208b6a997701
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 13:54:46 2019 +0800
| 
|     modify index1.html
| 
* commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 13:50:43 2019 +0800
| 
|     add index
| 
* commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c (HEAD -> readme)
  Author: tk8s <tk8s@tk8s.com>
  Date:   Mon Aug 26 13:35:52 2019 +0800
  
      add readme

[root@web git_test]# ll
total 4
-rw-r--r-- 1 root root 11 Aug 27 12:06 README
[root@web git_test]# cat .git/HEAD 
ref: refs/heads/readme
[root@web git_test]# cat .git/refs/heads/readme 
7e56f124868f2ace9896113ba3404f1bc9c50d9c
[root@web git_test]# git cat-file -t 7e56f124868f
commit
[root@web git_test]# git cat-file -p 7e56f124868f
tree 05930f0ac62c9169034d9b0570e0b0e687f6f6fa
author tk8s <tk8s@tk8s.com> 1566797752 +0800
committer tk8s <tk8s@tk8s.com> 1566797752 +0800

add readme

删除branch

[root@web git_test]# git branch -av
  dev    b82e5ce dev
  master 2fb91d6 move readme to readme.md
* readme 7e56f12 add readme
[root@web git_test]# git checkout master
Switched to branch 'master'
[root@web git_test]# git branch -a
  dev
* master
  readme
[root@web git_test]# git branch -D readme
Deleted branch readme (was 7e56f12).
[root@web git_test]# git branch -a
  dev
* master

修改commit message

[root@web git_test]# git branch -a
  dev
* master
[root@web git_test]# git log -1
commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move readme to readme.md

[root@web git_test]# git commit --amend
move file readme to readme.md

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Mon Aug 26 14:22:27 2019 +0800
#
# On branch master
# Changes to be committed:
#       renamed:    README -> README.md

[root@web git_test]# git log -1
commit 490003bc596334cd372f42bcfbc741aaa5a9f6c3 (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move file readme to readme.md

[root@web git_test]# git log -3
commit 490003bc596334cd372f42bcfbc741aaa5a9f6c3 (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move file readme to readme.md

commit 4712391e40f6a886542693af3ba4208b6a997701
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify index1.html

commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index

[root@web git_test]# git rebase -i 248abb7aa
r 4712391 modify index1.html
pick 490003b move file readme to readme.md

# Rebase 248abb7..490003b onto 248abb7 (2 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
~                                                                   
modify file index1.html

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Mon Aug 26 13:54:46 2019 +0800
#
# interactive rebase in progress; onto 248abb7
# Last command done (1 command done):
#    reword 4712391 modify index1.html
# Next command to do (1 remaining command):
#    pick 490003b move file readme to readme.md
# You are currently editing a commit while rebasing branch 'master' on '248abb7'.
#
# Changes to be committed:
#       modified:   index1.html
#
~                                                 
[root@web git_test]# git log -3
commit eb862c7a3030d98225933891e2b6909be68667eb (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move file readme to readme.md

commit 99610626f444a1a9c8a026c1b83010026ba61090
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify file index1.html

commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index

commit 合并

[root@web git_test]# git log
commit eb862c7a3030d98225933891e2b6909be68667eb (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 14:22:27 2019 +0800

    move file readme to readme.md

commit 99610626f444a1a9c8a026c1b83010026ba61090
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:54:46 2019 +0800

    modify file index1.html

commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add index

commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme
[root@web git_test]# git rebase -i 7e56f124868f
pick 248abb7 add index
s 9961062 modify file index1.html
s eb862c7 move file readme to readme.md

# Rebase 7e56f12..eb862c7 onto 7e56f12 (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
              
# This is a combination of 3 commits.
add web page
# This is the 1st commit message:

add index

# This is the commit message #2:

modify file index1.html

# This is the commit message #3:

move file readme to readme.md

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Mon Aug 26 13:50:43 2019 +0800
#
# interactive rebase in progress; onto 7e56f12
# Last commands done (3 commands done):
#    squash 9961062 modify file index1.html
#    squash eb862c7 move file readme to readme.md
# No commands remaining.
# You are currently rebasing branch 'master' on '7e56f12'.
#
# Changes to be committed:
#       renamed:    README -> README.md
#       new file:   index1.html
#       new file:   index2.html
#

[root@web git_test]# git log
commit a9c2791fee49a70db4fbfb25cd2b0361c496a9d2 (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add web page
    
    add index
    
    modify file index1.html
    
    move file readme to readme.md

commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme

[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root  9 Aug 27 14:17 index1.html
-rw-r--r-- 1 root root  6 Aug 27 14:15 index2.html
-rw-r--r-- 1 root root 11 Aug 27 14:17 README.md
[root@web git_test]# cat README.md 
“test”
[root@web git_test]# echo "test,ok" > README.md 
[root@web git_test]# git add README.md
[root@web git_test]# git commit -m "update README.md"
[master 33cc303] update README.md
 1 file changed, 1 insertion(+), 1 deletion(-)
[root@web git_test]# git log
commit 33cc30307f9cee7d8929d92de7312efb6add8c77 (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Tue Aug 27 14:26:12 2019 +0800

    update README.md

commit a9c2791fee49a70db4fbfb25cd2b0361c496a9d2
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add web page
    
    add index
    
    modify file index1.html
    
    move file readme to readme.md

commit 7e56f124868f2ace9896113ba3404f1bc9c50d9c
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    add readme

[root@web git_test]# git rebase -i 7e56f12
pick 7e56f12
s 33cc303 update README.md
pick a9c2791 add web page

# Rebase 7e56f12..33cc303 onto 7e56f12 (2 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
[root@web git_test]# git status
interactive rebase in progress; onto 7e56f12
Last command done (1 command done):
   pick 7e56f12 
Next commands to do (2 remaining commands):
   squash 33cc303 update README.md
   pick a9c2791 add web page
  (use "git rebase --edit-todo" to view and edit)
You are currently rebasing branch 'master' on '7e56f12'.
  (all conflicts fixed: run "git rebase --continue")

nothing to commit, working tree clean
[root@web git_test]# git rebase --continue
# This is a combination of 2 commits.
README
# This is the 1st commit message:

add readme

# This is the commit message #2:

update README.md

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Mon Aug 26 13:35:52 2019 +0800
#
# interactive rebase in progress; onto 7e56f12
# Last commands done (2 commands done):
#    pick 7e56f12
#    squash 33cc303 update README.md
# Next command to do (1 remaining command):
#    pick a9c2791 add web page
# You are currently rebasing branch 'master' on '7e56f12'.
#
#
# Initial commit
#
# Changes to be committed:
#       new file:   README

[root@web git_test]# git log
commit 488bca44d53b2e15bfe01cc5b92a598a1d2a43b8 (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add web page
    
    add index
    
    modify file index1.html
    
    move file readme to readme.md

commit 5fcb7a12635e5fa0a5de38c0f7868133871ca75d
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    README
    
    add readme
    
    update README.md

暂存区和HEAD比较

[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root 9 Aug 27 14:57 index1.html
-rw-r--r-- 1 root root 6 Aug 27 14:57 index2.html
-rw-r--r-- 1 root root 8 Aug 27 14:57 README.md
[root@web git_test]# git status
On branch master
nothing to commit, working tree clean
[root@web git_test]# echo "test01,ok" > index1.html 
[root@web git_test]# git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   index1.html

no changes added to commit (use "git add" and/or "git commit -a")
[root@web git_test]# git add index1.html

[root@web git_test]# git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   index1.html

[root@web git_test]# git diff --cached
diff --git a/index1.html b/index1.html
index a851fb8..8c9c2bb 100644
--- a/index1.html
+++ b/index1.html
@@ -1 +1 @@
-test1,ok
+test01,ok
[root@web git_test]# git commit -m "update index1.html"
[master 4ac967f] update index1.html
 1 file changed, 1 insertion(+), 1 deletion(-)
[root@web git_test]# git status
On branch master
nothing to commit, working tree clean
[root@web git_test]# git log
commit 4ac967f4c4f51b25c51bf32ec647f58f04145dae (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Tue Aug 27 15:06:33 2019 +0800

    update index1.html

commit 488bca44d53b2e15bfe01cc5b92a598a1d2a43b8
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add web page
    
    add index
    
    modify file index1.html
    
    move file readme to readme.md

commit 5fcb7a12635e5fa0a5de38c0f7868133871ca75d
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    README
    
    add readme
    
    update README.md
[root@web git_test]# 

工作区与暂存区比较

[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root 10 Aug 27 15:04 index1.html
-rw-r--r-- 1 root root  6 Aug 27 14:57 index2.html
-rw-r--r-- 1 root root  8 Aug 27 14:57 README.md
[root@web git_test]# git status
On branch master
nothing to commit, working tree clean
[root@web git_test]# echo "test03" > index3.html
[root@web git_test]# git add index3.html

[root@web git_test]# echo "test03,ok" > index3.html
[root@web git_test]# git diff
diff --git a/index3.html b/index3.html
index 23bc844..0da803b 100644
--- a/index3.html
+++ b/index3.html
@@ -1 +1 @@
-test03
+test03,ok

[root@web git_test]# git add index3.html
[root@web git_test]# git commit -m "add index3.html"
[master 5653f6b] add index3.html
 1 file changed, 1 insertion(+)
 create mode 100644 index3.html
[root@web git_test]# git status
On branch master
nothing to commit, working tree clean

暂存区恢复到HEAD

[root@web git_test]# ll 
total 16
-rw-r--r-- 1 root root 10 Aug 27 15:04 index1.html
-rw-r--r-- 1 root root  6 Aug 27 14:57 index2.html
-rw-r--r-- 1 root root 10 Aug 27 15:12 index3.html
-rw-r--r-- 1 root root  8 Aug 27 14:57 README.md
[root@web git_test]# echo "1" > index1.html 
[root@web git_test]# echo "2" > index2.html 
[root@web git_test]# echo "3" > index3.html 

[root@web git_test]# git add index1.html index2.html index3.html
[root@web git_test]# git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   index1.html
	modified:   index2.html
	modified:   index3.html
[root@web git_test]# git reset HEAD
Unstaged changes after reset:
M	index1.html
M	index2.html
M	index3.html
[root@web git_test]# git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   index1.html
	modified:   index2.html
	modified:   index3.html

no changes added to commit (use "git add" and/or "git commit -a")

工作区恢复到暂存区

[root@web git_test]# git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   index1.html
	modified:   index2.html
	modified:   index3.html

no changes added to commit (use "git add" and/or "git commit -a")
[root@web git_test]# git add index1.html index2.html index3.html
[root@web git_test]# git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   index1.html
	modified:   index2.html
	modified:   index3.html
[root@web git_test]# echo "01" > index1.html 
[root@web git_test]# echo "02" > index2.html 
[root@web git_test]# echo "03" > index3.html 
[root@web git_test]# git diff
diff --git a/index1.html b/index1.html
index d00491f..8a0f05e 100644
--- a/index1.html
+++ b/index1.html
@@ -1 +1 @@
-1
+01
diff --git a/index2.html b/index2.html
index 0cfbf08..9e22bcb 100644
--- a/index2.html
+++ b/index2.html
@@ -1 +1 @@
-2
+02
diff --git a/index3.html b/index3.html
index 00750ed..75016ea 100644
--- a/index3.html
+++ b/index3.html
@@ -1 +1 @@
-3
+03
[root@web git_test]# git checkout -- index1.html index2.html index3.html
[root@web git_test]# git diff
[root@web git_test]# git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   index1.html
	modified:   index2.html
	modified:   index3.html

[root@web git_test]# git commit -m "update 3 htmls"

取消暂存区的修改

[root@web git_test]# echo "01" > index1.html 
[root@web git_test]# echo "02" > index2.html 
[root@web git_test]# echo "03" > index3.html 
[root@web git_test]# git add index1.html index2.html index3.html
[root@web git_test]# git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   index1.html
	modified:   index2.html
	modified:   index3.html
[root@web git_test]# git diff --cached
diff --git a/index1.html b/index1.html
index d00491f..8a0f05e 100644
--- a/index1.html
+++ b/index1.html
@@ -1 +1 @@
-1
+01
diff --git a/index2.html b/index2.html
index 0cfbf08..9e22bcb 100644
--- a/index2.html
+++ b/index2.html
@@ -1 +1 @@
-2
+02
diff --git a/index3.html b/index3.html
index 00750ed..75016ea 100644
--- a/index3.html
+++ b/index3.html
@@ -1 +1 @@
-3
+03

[root@web git_test]# git reset HEAD -- index1.html index2.html index3.html
Unstaged changes after reset:
M	index1.html
M	index2.html
M	index3.html
[root@web git_test]# git diff --cached

删除commit

[root@web git_test]# git log
commit e53b0e62f5a7587ef2357791ddd9f2171785034e (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Tue Aug 27 15:35:03 2019 +0800

    update 3 htmls

commit 5653f6b879067725e7511f9e017e09168b76f86a
Author: tk8s <tk8s@tk8s.com>
Date:   Tue Aug 27 15:13:11 2019 +0800

    add index3.html

commit 4ac967f4c4f51b25c51bf32ec647f58f04145dae
Author: tk8s <tk8s@tk8s.com>
Date:   Tue Aug 27 15:06:33 2019 +0800

    update index1.html

commit 488bca44d53b2e15bfe01cc5b92a598a1d2a43b8
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add web page
    
    add index
    
    modify file index1.html
    
    move file readme to readme.md

commit 5fcb7a12635e5fa0a5de38c0f7868133871ca75d
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    README
    
    add readme
    
    update README.md

[root@web git_test]# git reset --hard 488bca4
HEAD is now at 488bca4 add web page
[root@web git_test]# git log
commit 488bca44d53b2e15bfe01cc5b92a598a1d2a43b8 (HEAD -> master)
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:50:43 2019 +0800

    add web page
    
    add index
    
    modify file index1.html
    
    move file readme to readme.md

commit 5fcb7a12635e5fa0a5de38c0f7868133871ca75d
Author: tk8s <tk8s@tk8s.com>
Date:   Mon Aug 26 13:35:52 2019 +0800

    README
    
    add readme
    
    update README.md
[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root 9 Aug 27 15:42 index1.html
-rw-r--r-- 1 root root 6 Aug 27 15:42 index2.html
-rw-r--r-- 1 root root 8 Aug 27 14:57 README.md

commit之间的差别

[root@web git_test]# git log --all --graph 
* commit 488bca44d53b2e15bfe01cc5b92a598a1d2a43b8 (HEAD -> master)
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 13:50:43 2019 +0800
| 
|     add web page
|     
|     add index
|     
|     modify file index1.html
|     
|     move file readme to readme.md
| 
* commit 5fcb7a12635e5fa0a5de38c0f7868133871ca75d
  Author: tk8s <tk8s@tk8s.com>
  Date:   Mon Aug 26 13:35:52 2019 +0800
  
      README
      
      add readme
      
      update README.md
  
* commit b82e5ce65db9682c90e4984cc344763dade4dc61 (dev)
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 15:14:11 2019 +0800
| 
|     dev
| 
* commit 2fb91d6cd462e10a1fdc70e4ab364539cc2a459e
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 14:22:27 2019 +0800
| 
|     move readme to readme.md
| 
* commit 4712391e40f6a886542693af3ba4208b6a997701
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 13:54:46 2019 +0800
| 
|     modify index1.html
| 
* commit 248abb7aa65a357a49d0d27b1b5e9d8b5af7fcef
| Author: tk8s <tk8s@tk8s.com>
| Date:   Mon Aug 26 13:50:43 2019 +0800
| 

[root@web git_test]# git diff 7e56f124868 2fb91d6cd46
diff --git a/README b/README.md
similarity index 100%
rename from README
rename to README.md
diff --git a/index1.html b/index1.html
new file mode 100644
index 0000000..a851fb8
--- /dev/null
+++ b/index1.html
@@ -0,0 +1 @@
+test1,ok
diff --git a/index2.html b/index2.html
new file mode 100644
index 0000000..180cf83
--- /dev/null
+++ b/index2.html
@@ -0,0 +1 @@
+test2

正确删除文件

[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root 9 Aug 27 15:42 index1.html
-rw-r--r-- 1 root root 6 Aug 27 15:42 index2.html
-rw-r--r-- 1 root root 8 Aug 27 14:57 README.md
[root@web git_test]# git rm README.md
rm 'README.md'
[root@web git_test]# git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	deleted:    README.md

恢复删除的文件

[root@web git_test]# ll
total 8
-rw-r--r-- 1 root root 9 Aug 27 15:42 index1.html
-rw-r--r-- 1 root root 6 Aug 27 15:42 index2.html
[root@web git_test]# git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	deleted:    README.md

[root@web git_test]# git restore --staged README.md

[root@web git_test]# ll
total 8
-rw-r--r-- 1 root root 9 Aug 27 15:42 index1.html
-rw-r--r-- 1 root root 6 Aug 27 15:42 index2.html
[root@web git_test]# ll
total 8
-rw-r--r-- 1 root root 9 Aug 27 15:42 index1.html
-rw-r--r-- 1 root root 6 Aug 27 15:42 index2.html
[root@web git_test]# git branch
  dev
* master
[root@web git_test]# git checkout dev
Switched to branch 'dev'
[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root 9 Aug 27 15:42 index1.html
-rw-r--r-- 1 root root 6 Aug 27 15:42 index2.html
-rw-r--r-- 1 root root 4 Aug 27 15:53 README.md
[root@web git_test]# git checkout master
Switched to branch 'master'
[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root 9 Aug 27 15:42 index1.html
-rw-r--r-- 1 root root 6 Aug 27 15:42 index2.html
-rw-r--r-- 1 root root 8 Aug 27 15:53 README.md

存储当前工作状态

[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root 9 Aug 27 15:42 index1.html
-rw-r--r-- 1 root root 6 Aug 27 15:42 index2.html
-rw-r--r-- 1 root root 8 Aug 27 15:53 README.md
[root@web git_test]# echo "test02,ok,ok" > index2.html
[root@web git_test]# git diff
diff --git a/index2.html b/index2.html
index 180cf83..a2214f5 100644
--- a/index2.html
+++ b/index2.html
@@ -1 +1 @@
-test2
+test02,ok,ok

[root@web git_test]# git stash
Saved working directory and index state WIP on master: 488bca4 add web page
[root@web git_test]# git diff
[root@web git_test]# git status
On branch master
nothing to commit, working tree clean
[root@web git_test]# git stash list
stash@{0}: WIP on master: 488bca4 add web page
[root@web git_test]# git stash apply
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   index2.html

no changes added to commit (use "git add" and/or "git commit -a")

[root@web git_test]# git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   index2.html

no changes added to commit (use "git add" and/or "git commit -a")

[root@web git_test]# git reset --hard HEAD
HEAD is now at 488bca4 add web page
[root@web git_test]# git status
On branch master
nothing to commit, working tree clean
[root@web git_test]# git stash list
stash@{0}: WIP on master: 488bca4 add web page
[root@web git_test]# git stash pop
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   index2.html

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (92a76d0f8adcb49463be866737956aaf2841c703)
[root@web git_test]# git stash list

.gitignore 指定不需要管理的文件

[root@web git_test]# mkdir test
[root@web git_test]# echo "test" > test/test.html
[root@web git_test]# git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	test/

nothing added to commit but untracked files present (use "git add" to track)

[root@web git_test]# echo "test" > .gitignore
[root@web git_test]# git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.gitignore

nothing added to commit but untracked files present (use "git add" to track)
[root@web git_test]# rm -rf test/
[root@web git_test]# ll
total 12
-rw-r--r-- 1 root root  9 Aug 27 15:42 index1.html
-rw-r--r-- 1 root root 13 Aug 27 16:05 index2.html
-rw-r--r-- 1 root root  8 Aug 27 15:53 README.md
[root@web git_test]# echo "test" > test
[root@web git_test]# ll
total 16
-rw-r--r-- 1 root root  9 Aug 27 15:42 index1.html
-rw-r--r-- 1 root root 13 Aug 27 16:05 index2.html
-rw-r--r-- 1 root root  8 Aug 27 15:53 README.md
-rw-r--r-- 1 root root  5 Aug 27 16:24 test

[root@web git_test]# echo "test/" > .gitignore
[root@web git_test]# cat .gitignore 
test/
[root@web git_test]# git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.gitignore
	test

nothing added to commit but untracked files present (use "git add" to track)

git备份

[root@web git_test]# git add .
[root@web git_test]# git commit -m "clone"
[master bf7c12b] clone
 2 files changed, 2 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 test
[root@web git_test]# git status
On branch master
nothing to commit, working tree clean

[root@web git_test]# git clone --bare file:///root/git_test/.git  test.git
Cloning into bare repository 'test.git'...
remote: Enumerating objects: 27, done.
remote: Counting objects: 100% (27/27), done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 27 (delta 3), reused 0 (delta 0)
Receiving objects: 100% (27/27), done.
Resolving deltas: 100% (3/3), done.
[root@web git_test]# ll
total 16
-rw-r--r-- 1 root root   9 Aug 27 15:42 index1.html
-rw-r--r-- 1 root root  13 Aug 27 16:05 index2.html
-rw-r--r-- 1 root root   8 Aug 27 15:53 README.md
-rw-r--r-- 1 root root   5 Aug 27 16:24 test
drwxr-xr-x 7 root root 138 Aug 27 16:36 test.git

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值