Git 常用命令

  1. 命令名称作用

git config --global user.name 用户名 设置用户签名

git config --global user.email 邮箱 设置用户签名

git config --global http.sslVerify false 关闭ssl认证

git init 初始化本地库

git status 查看本地库状态

git add 文件名 添加到暂存区

git commit -m "日志信息" 文件名 提交到本地库

git reflog 查看历史记录

git reset --hard 版本号 版本穿梭

git tag 标签名称

  1. 设置用户签名

基本语法

git config --global user.name 用户名

git config --global user.email 邮箱

git config --global http.sslVerify false

2 )案例实操

全局范围的签名设置:

$ git config --global user.name aw0474

$ git config --global user.email aw0474@126.com

$ cat ~/.gitconfig

 

说明:

签名的作用是区分不同操作者身份。用户的签名信息在每一个版本的提交信息中能够看到,以此确认本次提交是谁做的。Git 首次安装必须设置一下用户签名,否则无法提交代码。

注意:这里设置用户签名和将来登录 GitHub(或其他代码托管中心)的账号没有任

何关系。

  1. 初始化本地库
  1. 初始化工作区

Jocker@Jocker MINGW64 /d/tmp/git-test01

$ git init

Initialized empty Git repository in D:/tmp/git-test01/.git/

Jocker@Jocker MINGW64 /d/tmp/git-test01 (master)

$ ll -a

total 4

drwxr-xr-x 1 Jocker 197121 0 Jun 13 09:42 ./

drwxr-xr-x 1 Jocker 197121 0 Jun 13 09:42 ../

drwxr-xr-x 1 Jocker 197121 0 Jun 13 09:42 .git/

  1. 状态查询

$ git status

On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

新增文件( (hello.txt )

$ vim hello.txt

hello git! hello offcn!

hello git! hello offcn!

再次查看( 检测到未追踪的文件) )

$ git status

On branch master

No commits yet

Untracked files:

  (use "git add <file>..." to include in what will be committed)

        hello.txt

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

  1.  添加 暂存区

将工作区的文件添加到暂存区

$ git add hello.txt

warning: LF will be replaced by CRLF in hello.txt.

The file will have its original line endings in your working directory

Jocker@Jocker MINGW64 /d/tmp/git-test01 (master)

$ git status

On branch master

No commits yet

Changes to be committed:

  (use "git rm --cached <file>..." to unstage)

        new file:   hello.txt

  1. 提交到本地库

将暂存区的 文件 提交到本地库

git commit -m " 日志信息" 文件名

$ git commit -m "first commit" hello.txt

warning: LF will be replaced by CRLF in hello.txt.

The file will have its original line endings in your working directory

[master (root-commit) 5fe6785] first commit

 1 file changed, 3 insertions(+)

 create mode 100644 hello.txt

$ git status

On branch master

nothing to commit, working tree clean

修改文件( (hello.txt )

$ vim hello.txt

hello git! hello offcn! 2222222222222

hello git! hello offcn!

查看状态( 检测到工作区有文件被修改) )

$ 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:   hello.txt

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

将修改的文件再次添加暂存区

$ git add hello.txt

warning: LF will be replaced by CRLF in hello.txt.

The file will have its original line endings in your working directory

Jocker@Jocker MINGW64 /d/tmp/git-test01 (master)

$ git status

On branch master

Changes to be committed:

  (use "git restore --staged <file>..." to unstage)

        modified:   hello.txt

$ git commit -m "second commit" hello.txt

warning: LF will be replaced by CRLF in hello.txt.

The file will have its original line endings in your working directory

[master 13f0092] second commit

 1 file changed, 1 insertion(+), 1 deletion(-)

Jocker@Jocker MINGW64 /d/tmp/git-test01 (master)

$ git status

On branch master

nothing to commit, working tree clean

  1. 历史版本
  1. 查看历史版本

基本语法

git reflog 查看版本信息

git log 查看版本详细信息

$ git reflog

13f0092 (HEAD -> master) HEAD@{0}: commit: second commit

5fe6785 HEAD@{1}: commit (initial): first commit

$ git log

commit 13f0092cce81e109c6671495d3220f2a244a605f (HEAD -> master)

Author: aw0474 <aw0474@126.com>

Date:   Mon Jun 13 09:56:55 2022 +0800

    second commit

commit 5fe678536fa10470507da744425394d6a95ac5ee

Author: aw0474 <aw0474@126.com>

Date:   Mon Jun 13 09:51:43 2022 +0800

    first commit

  1. 版本穿梭

基本语法

git reset --hard 版本号

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值