[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_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
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
#
~
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
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]# 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]# 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
[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