Git安装
[root@Programer ~]
en_US.UTF-8
[root@Programer ~]
[root@Programer ~]
[root@Programer ~]
LANG="zh_CN.UTF-8"
[root@Programer ~]
[root@Programer ~]
zh_CN.UTF-8
[root@Programer ~]
[root@Programer ~]
...
Total packages: 8,265
[root@Programer ~]
...
Complete!
[root@Programer ~]
git version 2.31.1
[root@Programer ~]
Git工作流程
Git基础配置
--local:仓库级
--global:全局级
--system:系统级
[root@programer ~]
[root@programer ~]
[root@programer ~]
[root@programer ~]
user.name=xuwenpeng3
user.email=[email protected]
init.defaultbranch=master
[root@programer ~]
[user]
name = xuwenpeng3
email = [email protected]
[init]
defaultBranch = master
Git创建版本库
[root@programer ~]
[root@programer ~]
Initialized empty Git repository in /root/myproject/.git/
[root@programer ~]
myproject
[root@programer ~]
. .. .git
[root@programer ~]
. .. HEAD branches config description hooks info objects refs
[root@programer ~]
[root@programer ~]
. ..
[root@programer ~]
[root@programer mytest]
Initialized empty Git repository in /root/mytest/.git/
[root@programer mytest]
. .. .git
[root@programer mytest]
. .. HEAD branches config description hooks info objects refs
Git版本库操作
[root@programer ~]
[root@programer myproject]
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
[root@programer myproject]
[root@programer myproject]
readme.md
[root@programer myproject]
On branch master
No commits yet
Untracked files:
(use "git add ..." to include in what will be committed)
readme.md
nothing added to commit but untracked files present (use "git add" to track)
[root@programer myproject]
[root@programer myproject]
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached ..." to unstage)
new file: readme.md
[root@programer myproject]
[master (root-commit) 6c7fa0a] add readme
1 file changed, 1 insertion(+)
create mode 100644 readme.md
[root@programer myproject]
On branch master
nothing to commit, working tree clean
Git版本库查询
[root@programer myproject]
commit 6c7fa0a66645eb2dfa9c9f75f0cb1237b39a9489 (HEAD -> master)
Author: xuwenpeng3 <[email protected]>
Date: Wed Sep 20 10:18:02 2023 +0800
add readme
[root@programer myproject]
6c7fa0a66645eb2dfa9c9f75f0cb1237b39a9489 (HEAD -> master) add readme
[root@programer myproject]
6c7fa0a (HEAD -> master) add readme
Git练习(生成多个版本)
[root@programer ~]
[root@programer myproject]
[root@programer myproject]
[root@programer myproject]
[master f20ee5f] add test.txt
1 file changed, 1 insertion(+)
create mode 100644 test.txt
[root@programer myproject]
[root@programer myproject]
[root@programer myproject]
[master e88a5ff] modify test.txt
1 file changed, 1 deletion(-)
[root@programer myproject]
[root@programer myproject]
On branch master
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
[root@programer myproject]
[root@programer myproject]
[master d4a95fa] done test.txt
1 file changed, 1 insertion(+)
[root@programer myproject]
d4a95face5c9725263596ff340dcf9f2dd0e2552 (HEAD -> master) done test.txt
e88a5ff574fd24416de7e5834f5ef2144502f8dc modify test.txt
f20ee5f0034d7866381dcdd14bc09168f4563b0f add test.txt
6c7fa0a66645eb2dfa9c9f75f0cb1237b39a9489 add readme
[root@programer myproject]
d4a95fa (HEAD -> master) done test.txt
e88a5ff modify test.txt
f20ee5f add test.txt
6c7fa0a add readme
Git指针操作
查看Git指针信息
[root@programer ~]
[root@programer myproject]
d4a95face5c9725263596ff340dcf9f2dd0e2552 (HEAD -> master) done test.txt
e88a5ff574fd24416de7e5834f5ef2144502f8dc modify test.txt
f20ee5f0034d7866381dcdd14bc09168f4563b0f add test.txt
6c7fa0a66645eb2dfa9c9f75f0cb1237b39a9489 add readme
[root@programer myproject]
789
利用指针实现Git版本还原
--soft:缓存区和工作目录不受影响,reset后分支和HEAD指针移动到指定的commit,代码文件和reset之前一样,修改部分已加入到暂存区,通常用于重新提交。
--mixed:(默认)工作目录不受影响,reset后分支的HEAD指针移动到指定位置,代码文件内容和reset之前一样,修改部分未加入到暂存区
--hard:工作目录,缓存区均受影响。reset后分支和HEAD指针移动到指定commit,代码文件内容回退到指定commit,工作空间为clean状态。通常用于获取指定版本的代码文件
[root@programer myproject]
HEAD is now at 1c2535a modify test.txt
[root@programer myproject]
1c2535a (HEAD -> master) modify test.txt
5dc6adb add test.txt
023dbd9 add readme
[root@programer myproject]
456
[root@programer myproject]
1c2535a (HEAD -> master) HEAD@{0}: reset: moving to 1c2535a7c2
dc4b5a8 HEAD@{1}: commit: done test.txt
1c2535a (HEAD -> master) HEAD@{2}: commit: modify test.txt
5dc6adb HEAD@{3}: commit: add test.txt
023dbd9 HEAD@{4}: commit (initial): add readme
[root@programer myproject]
dc4b5a8 (HEAD -> master) HEAD@{0}: reset: moving to dc4b5a8
1c2535a HEAD@{1}: reset: moving to 1c2535a7c2
dc4b5a8 (HEAD -> master) HEAD@{2}: commit: done test.txt
1c2535a HEAD@{3}: commit: modify test.txt
5dc6adb HEAD@{4}: commit: add test.txt
023dbd9 HEAD@{5}: commit (initial): add readme
[root@programer myproject]
789
Git分支操作
[root@programer myproject]
On branch master
nothing to commit, working tree clean
[root@programer myproject]
* master dc4b5a8 done test.txt
[root@programer myproject]
[root@programer myproject]
[root@programer myproject]
feature dc4b5a8 done test.txt
hotfix dc4b5a8 done test.txt
* master dc4b5a8 done test.txt
[root@programer myproject]
Switched to branch 'hotfix'
[root@programer myproject]
feature dc4b5a8 done test.txt
* hotfix dc4b5a8 done test.txt
master dc4b5a8 done test.txt
[root@programer myproject]
Switched to branch 'feature'
[root@programer myproject]
* feature dc4b5a8 done test.txt
hotfix dc4b5a8 done test.txt
master dc4b5a8 done test.txt
[root@programer myproject]
[root@programer myproject]
develop dc4b5a8 done test.txt
* feature dc4b5a8 done test.txt
hotfix dc4b5a8 done test.txt
master dc4b5a8 done test.txt
[root@programer myproject]
Deleted branch develop (was dc4b5a8).
[root@programer myproject]
* feature dc4b5a8 done test.txt
hotfix dc4b5a8 done test.txt
master dc4b5a8 done test.txt
Git合并分支
[root@programer myproject]
Switched to branch 'hotfix'
[root@programer myproject]
[root@programer myproject]
[root@programer myproject]
[hotfix 49461bb] add haha.txt
1 file changed, 1 insertion(+)
create mode 100644 haha.txt
[root@programer myproject]
haha.txt readme.md test.txt
[root@programer myproject]
Switched to branch 'master'
[root@programer myproject]
[root@programer myproject]
[root@programer myproject]
error: pathspec 'add xixi.txt' did not match any file(s) known to git
[root@programer myproject]
[master fd88497] add xixi.txt
1 file changed, 1 insertion(+)
create mode 100644 xixi.txt
[root@programer myproject]
feature dc4b5a8 done test.txt
hotfix 49461bb add haha.txt
* master fd88497 add xixi.txt
[root@programer myproject]
Merge made by the 'recursive' strategy.
haha.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 haha.txt
[root@programer myproject]
haha.txt readme.md test.txt xixi.txt
[root@programer myproject]
haha
[root@programer myproject]
xixi
[root@programer myproject]
Switched to branch 'hotfix'
[root@programer myproject]
[root@programer myproject]
[root@programer myproject]
[hotfix 3be70ac] hotfix
1 file changed, 1 insertion(+)
create mode 100644 a.txt
[root@programer myproject]
feature dc4b5a8 done test.txt
* hotfix 3be70ac hotfix
master 416f3d7 Merge branch 'hotfix'
[root@programer myproject]
Switched to branch 'master'
[root@programer myproject]
feature dc4b5a8 done test.txt
hotfix 3be70ac hotfix
* master 416f3d7 Merge branch 'hotfix'
[root@programer myproject]
[root@programer myproject]
[root@programer myproject]
[master 93e8350] master
1 file changed, 1 insertion(+)
create mode 100644 a.txt
[root@programer myproject]
CONFLICT (add/add): Merge conflict in a.txt
Auto-merging a.txt
Automatic merge failed; fix conflicts and then commit the result.
[root@programer myproject]
<<<<<<< HEAD
xixixi
=======
hahaha
>>>>>>> hotfix
[root@programer myproject]
xixixi
hahaha
[root@programer myproject]
[root@programer myproject]
[master a35cf84] resolv conflict
[root@programer myproject]
Git标签操作
[root@programer myproject]
[root@programer myproject]
[root@programer myproject]
v1
[root@programer myproject]
[root@programer myproject]
v1
v2
[root@programer myproject]
Deleted tag 'v2' (was a35cf84)