Git的基本使用

相关指令

创建git仓库

git init

(base) [root@CentOS-wangml gitDir]# git init
Initialized empty Git repository in /home/lighthouse/study/git/gitDir/.git/

查看仓库状态

git status

(base) [root@CentOS-wangml gitDir]# git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

将工作空间的修改添加到暂存区

git add

(base) [root@CentOS-wangml gitDir]# touch a.txt
(base) [root@CentOS-wangml gitDir]# ls
a.txt
(base) [root@CentOS-wangml gitDir]# touch b.txt
(base) [root@CentOS-wangml gitDir]# git add a.txt
(base) [root@CentOS-wangml gitDir]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   a.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	b.txt
(base) [root@CentOS-wangml gitDir]# git add b.txt
(base) [root@CentOS-wangml gitDir]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   a.txt
#	new file:   b.txt
#

将暂存区内容提交到版本库

git commit -m ‘备注‘

(base) [root@CentOS-wangml gitDir]# git commit -m ‘create a.txt b.txt‘
[master (root-commit) 800f2d8] create a.txt b.txt
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a.txt
 create mode 100644 b.txt
(base) [root@CentOS-wangml gitDir]# git status
# On branch master
nothing to commit, working directory clean

查看版本库信息

注意:git log --oneline只会显示从版本库最初版本到当前版本

(base) [root@CentOS-wangml gitDir]# git log
commit 800f2d80f661a0cf686612fc3b4ae9a6c28f5bf0
Author: wangml <myemal@my.com>
Date:   Fri Jul 9 15:43:04 2021 +0800

    create a.txt b.txt
(base) [root@CentOS-wangml gitDir]# git log --oneline
800f2d8 create a.txt b.txt

设置用户信息

(base) [root@CentOS-wangml gitDir]# git config --global user.name ‘wangml‘ 
(base) [root@CentOS-wangml gitDir]# git config --global user.email ‘wangmlem@163.com‘

同步历史版本到工作空间

git checkout 版本号

(base) [root@CentOS-wangml gitDir]# git log --oneline
097c5f9 create d.txt
1360aa5 create c.txt
800f2d8 create a.txt b.txt
(base) [root@CentOS-wangml gitDir]# ls
a.txt  b.txt  c.txt  d.txt
(base) [root@CentOS-wangml gitDir]# git checkout 800f2d8
Note: checking out ‘800f2d8‘.

You are in ‘detached HEAD‘ state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 800f2d8... create a.txt b.txt
(base) [root@CentOS-wangml gitDir]# ls
a.txt  b.txt
(base) [root@CentOS-wangml gitDir]# git checkout 097c5f9
Previous HEAD position was 800f2d8... create a.txt b.txt
HEAD is now at 097c5f9... create d.txt
(base) [root@CentOS-wangml gitDir]# ls
a.txt  b.txt  c.txt  d.txt

Git的基本使用

上一篇:LC981-基于时间的键值存储


下一篇:k8s--持久化存储