Linux学习-HIS系统部署(1)

Git安装
#安装中文支持(选做)
[root@Programer ~]# echo $LANG                              #查看当前系统语言及编码
en_US.UTF-8
[root@Programer ~]# yum -y install langpacks-zh_CN.noarch   #安装中文支持
[root@Programer ~]# vim /etc/locale.conf                    #配置系统使用中文及编码
[root@Programer ~]# cat /etc/locale.conf 
LANG="zh_CN.UTF-8"
[root@Programer ~]# reboot                                  #重启使语言配置生效

[root@Programer ~]# echo $LANG                              #确认使用中文编码
zh_CN.UTF-8
[root@Programer ~]# 

#yum源中集成了Git软件包,使用yum安装Git
[root@Programer ~]# yum clean all; yum repolist -v          #插件yum源是否可用
...
Total packages: 8,265
[root@Programer ~]# yum -y install git                      #使用yum安装Git
...
Complete!
[root@Programer ~]# git --version                           #查看Git版本
git version 2.31.1
[root@Programer ~]# git --help                              #查看Git命令帮助信息
Git工作流程

Linux学习-HIS系统部署(1)_第1张图片

Git基础配置
# Git基础配置
--local:仓库级
--global:全局级
--system:系统级
# 设置用户名
[root@programer ~]# git config --global user.name xuwenpeng3
# 设置用户信箱
[root@programer ~]# git config --global user.email [email protected]
# 设置版本库默认分支
[root@programer ~]# git config --global init.defaultBranch master
# 查看已有Git配置
[root@programer ~]# git config --list
user.name=xuwenpeng3
user.email=[email protected]
init.defaultbranch=master
# 查看Git配置持久化文件
[root@programer ~]# cat ~/.gitconfig 
[user]
        name = xuwenpeng3
        email = [email protected]
[init]
        defaultBranch = master
Git创建版本库
# ------Git初始化空版本库
[root@programer ~]# ls
# 初始化空版本库
[root@programer ~]# git init myproject
Initialized empty Git repository in /root/myproject/.git/
[root@programer ~]# ls
myproject
# 查看版本库信息
[root@programer ~]# ls -a myproject/
.  ..  .git
[root@programer ~]# ls -a myproject/.git
.  ..  HEAD  branches  config  description  hooks  info  objects  refs
# ------将已胡目录制作成版本库
[root@programer ~]# mkdir mytest
[root@programer ~]# ls -a mytest
.  ..
[root@programer ~]# cd mytest
# 将已有空的目录初使化为git库
[root@programer mytest]# git init
Initialized empty Git repository in /root/mytest/.git/
[root@programer mytest]# ls -a
.  ..  .git
[root@programer mytest]# ls -a .git
.  ..  HEAD  branches  config  description  hooks  info  objects  refs
Git版本库操作
# Git基础命令使用
[root@programer ~]# cd myproject/
[root@programer myproject]# git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)
# 创建readme文件
[root@programer myproject]# echo "Learning Git" >> readme.md
[root@programer myproject]# ls
readme.md
[root@programer myproject]# git status
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]# git add readme.md 
# 查看Git本地仓库状态
[root@programer myproject]# git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached ..." to unstage)
        new file:   readme.md
# 将暂停区文件提交到本地仓库
[root@programer myproject]# git commit -m "add readme"
[master (root-commit) 6c7fa0a] add readme
 1 file changed, 1 insertion(+)
 create mode 100644 readme.md
[root@programer myproject]# git status
On branch master
nothing to commit, working tree clean
Git版本库查询
# 查看本地Git版本库信息
[root@programer myproject]# git log      # 本地版本库提交记录
commit 6c7fa0a66645eb2dfa9c9f75f0cb1237b39a9489 (HEAD -> master)
Author: xuwenpeng3 <[email protected]>
Date:   Wed Sep 20 10:18:02 2023 +0800

    add readme
# 本地版本库提交记录(简略)
[root@programer myproject]# git log --pretty=oneline
6c7fa0a66645eb2dfa9c9f75f0cb1237b39a9489 (HEAD -> master) add readme
# 本地版本库提交记录(极简)
[root@programer myproject]# git log --oneline
6c7fa0a (HEAD -> master) add readme
Git练习(生成多个版本)
[root@programer ~]# cd myproject
# 创建test.txt文件
[root@programer myproject]# echo 123 > test.txt
# 添加test.txt至暂存区
[root@programer myproject]# git add test.txt
# 生成新版本
[root@programer myproject]# git commit -m "add test.txt"
[master f20ee5f] add test.txt
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt
[root@programer myproject]# echo 456>test.txt

[root@programer myproject]# git add .
[root@programer myproject]# git commit -m "modify test.txt"
[master e88a5ff] modify test.txt
 1 file changed, 1 deletion(-)
[root@programer myproject]# echo 789 > test.txt
[root@programer myproject]# git commit -m "done test.txt"
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]# git add ./
[root@programer myproject]# git commit -m "done test.txt"
[master d4a95fa] done test.txt
 1 file changed, 1 insertion(+)
[root@programer myproject]# git log --pretty=oneline
d4a95face5c9725263596ff340dcf9f2dd0e2552 (HEAD -> master) done test.txt
e88a5ff574fd24416de7e5834f5ef2144502f8dc modify test.txt
f20ee5f0034d7866381dcdd14bc09168f4563b0f add test.txt
6c7fa0a66645eb2dfa9c9f75f0cb1237b39a9489 add readme
[root@programer myproject]# git log --oneline
d4a95fa (HEAD -> master) done test.txt
e88a5ff modify test.txt
f20ee5f add test.txt
6c7fa0a add readme
Git指针操作
查看Git指针信息
# 使用git log命令查看HEAD指针
[root@programer ~]# cd myproject
# 查看git指针
[root@programer myproject]# git log --pretty=oneline
d4a95face5c9725263596ff340dcf9f2dd0e2552 (HEAD -> master) done test.txt
e88a5ff574fd24416de7e5834f5ef2144502f8dc modify test.txt
f20ee5f0034d7866381dcdd14bc09168f4563b0f add test.txt
6c7fa0a66645eb2dfa9c9f75f0cb1237b39a9489 add readme
[root@programer myproject]# cat test.txt
789
利用指针实现Git版本还原
# reset子命令用于版本还原
--soft:缓存区和工作目录不受影响,reset后分支和HEAD指针移动到指定的commit,代码文件和reset之前一样,修改部分已加入到暂存区,通常用于重新提交。
--mixed:(默认)工作目录不受影响,reset后分支的HEAD指针移动到指定位置,代码文件内容和reset之前一样,修改部分未加入到暂存区
--hard:工作目录,缓存区均受影响。reset后分支和HEAD指针移动到指定commit,代码文件内容回退到指定commit,工作空间为clean状态。通常用于获取指定版本的代码文件
# 还原到指定版本
[root@programer myproject]# git reset --hard 1c2535a7c2 
HEAD is now at 1c2535a modify test.txt
# 确认HEAD指针移动
[root@programer myproject]# git log --oneline
1c2535a (HEAD -> master) modify test.txt
5dc6adb add test.txt
023dbd9 add readme
[root@programer myproject]# cat test.txt
456

#reflog子命令用于获取HEAD指针移动轨迹
[root@programer myproject]# git reflog
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]# git reflog
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]# cat test.txt 
789
Git分支操作
# 查看当前分支信息,branch子命令
# 查看本地Git仓库信息
[root@programer myproject]# git status
On branch master
nothing to commit, working tree clean
# 查看分支信息
[root@programer myproject]# git branch -v
* master dc4b5a8 done test.txt
# 创建hotfix分支
[root@programer myproject]# git branch hotfix
[root@programer myproject]# git branch feature
[root@programer myproject]# git branch -v
  feature dc4b5a8 done test.txt
  hotfix  dc4b5a8 done test.txt
* master  dc4b5a8 done test.txt
# 切换分支
[root@programer myproject]# git checkout hotfix
Switched to branch 'hotfix'
[root@programer myproject]# git branch -v
  feature dc4b5a8 done test.txt
* hotfix  dc4b5a8 done test.txt
  master  dc4b5a8 done test.txt
[root@programer myproject]# git checkout feature
Switched to branch 'feature'
[root@programer myproject]# git branch -v
* feature dc4b5a8 done test.txt
  hotfix  dc4b5a8 done test.txt
  master  dc4b5a8 done test.txt
[root@programer myproject]# git branch develop
[root@programer myproject]# git branch -v
  develop dc4b5a8 done test.txt
* feature dc4b5a8 done test.txt
  hotfix  dc4b5a8 done test.txt
  master  dc4b5a8 done test.txt
# 删除develop分支
[root@programer myproject]# git branch -d develop
Deleted branch develop (was dc4b5a8).
[root@programer myproject]# git branch -v
* feature dc4b5a8 done test.txt
  hotfix  dc4b5a8 done test.txt
  master  dc4b5a8 done test.txt
Git合并分支
# 无冲突分支合并
# 切换到hotfix分支
[root@programer myproject]# git checkout hotfix
Switched to branch 'hotfix'
[root@programer myproject]# echo haha>haha.txt
# 添加haha到暂存区
[root@programer myproject]# git add .
# 生成新版本
[root@programer myproject]# git commit -m "add haha.txt"
[hotfix 49461bb] add haha.txt
 1 file changed, 1 insertion(+)
 create mode 100644 haha.txt
[root@programer myproject]# ls
haha.txt  readme.md  test.txt
# 切换到master分支
[root@programer myproject]# git checkout master
Switched to branch 'master'
[root@programer myproject]# echo xixi>xixi.txt
#添加至暂存区
[root@programer myproject]# git add .
[root@programer myproject]# git commit -n "add xixi.txt"
error: pathspec 'add xixi.txt' did not match any file(s) known to git
[root@programer myproject]# git commit -m "add xixi.txt"
[master fd88497] add xixi.txt
 1 file changed, 1 insertion(+)
 create mode 100644 xixi.txt
[root@programer myproject]# git branch -v
  feature dc4b5a8 done test.txt
  hotfix  49461bb add haha.txt
* master  fd88497 add xixi.txt
# 合并hotfix分支到master分支
[root@programer myproject]# git merge hotfix
Merge made by the 'recursive' strategy.
 haha.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 haha.txt
[root@programer myproject]# ls
haha.txt  readme.md  test.txt  xixi.txt
[root@programer myproject]# cat haha.txt
haha
[root@programer myproject]# cat xixi.txt
xixi
[root@programer myproject]# git checkout hotfix
Switched to branch 'hotfix'
[root@programer myproject]# echo "hahaha">a.txt
[root@programer myproject]# git add .
[root@programer myproject]# git commit -m "hotfix"
[hotfix 3be70ac] hotfix
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
[root@programer myproject]# git branch -v
  feature dc4b5a8 done test.txt
* hotfix  3be70ac hotfix
  master  416f3d7 Merge branch 'hotfix'
[root@programer myproject]# git checkout master
Switched to branch 'master'
[root@programer myproject]# git branch -v
  feature dc4b5a8 done test.txt
  hotfix  3be70ac hotfix
* master  416f3d7 Merge branch 'hotfix'
[root@programer myproject]# echo "xixixi">a.txt
[root@programer myproject]# git add .
[root@programer myproject]# git commit -m "master"
[master 93e8350] master
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
 # 有冲突分支合并(修改不同分支中相同文件的相同行)
[root@programer myproject]# git merge hotfix
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]# cat a.txt
<<<<<<< HEAD
xixixi
=======
hahaha
>>>>>>> hotfix
# 将a.txt文件内容合并成如下
[root@programer myproject]# vim a.txt
xixixi
hahaha
[root@programer myproject]# git add .
[root@programer myproject]# git commit -m "resolv conflict"
[master a35cf84] resolv conflict
[root@programer myproject]# 
Git标签操作
# 使用tag子命令管理标签
# 查看已有标签
[root@programer myproject]# git tag
# 创建v1标签
[root@programer myproject]# git tag v1
[root@programer myproject]# git tag
v1
[root@programer myproject]# git tag v2
[root@programer myproject]# git tag
v1
v2
# 删除v2标签
[root@programer myproject]# git tag -d v2
Deleted tag 'v2' (was a35cf84)

你可能感兴趣的:(Linux,Git,linux,学习,elasticsearch)