Git常用命令

命令名称作用
git config --global user.name 用户名设置用户签名
git config --global user.email 邮箱设置用户签名
git init初始化本地库
git status查看本地库状态
git add 文件名添加到暂存区
git commit -m “日志信息” 文件名提交到本地库
git reflog查看历史记录
git reset --hard 版本号版本穿梭

设置用户签名

基本语法:

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

配置完成查看:

cat ~/.gitconfig

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

这里设置用户签名和将来登录GitHub的账号没有任何关系。

初始化本地库

基本语法:

git init

查看.git文件

ll -a

查看本地库状态

基本语法:

git status

输出:

on branch master  表示当前本地库在master分支中
no commits yet 目前没有提交任何东西
nothing to commit (create/copy files and use "git add" to track) 没有什么需要提交

新建hello.txt文件后查看状态显示:

on branch master 
no commits yet 
untrack files:
  (use "git add <file>...") to include in what will be committed 表示git没有追踪此文件
                       hello.txt
nothing added to commit but untracked files present (use "git add" to track) 

添加暂存区

基本语法:

git add hello.txt

使用git status显示:

on branch master

no commit yet

changes to be commited:
  (use "git rm --cache <file>..." to unstage)
                 new file:        hello.txt 绿色说明当前已经追踪到文件

文件当前只是存在于暂存区中,暂存区文件是可以删除的,如果不想将hello.txt保存历史版本,可以将其删除

git rm --cached hello.txt

提交本地库

将暂存区文件提交到本地库
基本语法:

git commit -m "日志信息" 文件名
输出文件版本号
git commit -m "my first commit" hello.txt

查看状态:

git status
on branch status
nothing to commit, working tree clean

查看日志:
在这里插入图片描述

修改文件

vim hello.txt
# 这里随意修改文件内容

查看文件状态:

git status

在这里插入图片描述
红色表示修改还没被添加到暂存区中。

git add hello.txt
git status

在这里插入图片描述
提交本地库:

git commit -m "second commit" hello.txt

在这里插入图片描述

git是按行来维护文件的。

git status
git reflog

在这里插入图片描述
可以看出当前有两个版本
指针指向第二个版本

查看历史版本

基本语法:

git reflog 查看版本信息
git log 查看版本详细信息

在这里插入图片描述

版本穿梭

基本语法:

git reflog 首先查看当前历史记录
git reset --hard 版本号
git reflog 切换完成后再查看版本历史记录

在这里插入图片描述
Git切换版本,底层其实就是移动HEAD指针
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值