IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> Git笔记 -> 正文阅读

[开发工具]Git笔记

Git

1、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 版本号版本穿梭

1.1、设置用户签名

首次安装必须设置用户签名:

Li@Li-911m MINGW64 ~/Desktop
$ git config --global user.name Li

Li@Li-911m MINGW64 ~/Desktop
$ git config --global user.email li@li.com

1.2、初始化本地库

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java
$ git init
Initialized empty Git repository in G:/work/coding/Git-Space/Java/.git/

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ ll -a
total 4
drwxr-xr-x 1 Li 197609 0 Mar  4 16:53 ./
drwxr-xr-x 1 Li 197609 0 Mar  4 16:53 ../
drwxr-xr-x 1 Li 197609 0 Mar  4 16:53 .git/

请添加图片描述

1.3、查看本地库状态

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git status
On branch master

No commits yet

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

新增一个文件后:

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        helloGit.text

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

1.4、添加暂存区

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git add helloGit.text
warning: LF will be replaced by CRLF in helloGit.text.
The file will have its original line endings in your working directory

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   helloGit.text

删除文件(只是暂存区文件的删除,并不是工作区):

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git rm --cached helloGit.text
rm 'helloGit.text'

1.5、提交本地库

将暂存区文件提交到本地库形成历史版本:

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git commit -m "first commit" helloGit.text
warning: LF will be replaced by CRLF in helloGit.text.
The file will have its original line endings in your working directory
[master (root-commit) a247ad1] first commit
 1 file changed, 15 insertions(+)
 create mode 100644 helloGit.text
Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git status
On branch master
nothing to commit, working tree clean

查看历史版本:

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git reflog
a247ad1 (HEAD -> master) HEAD@{0}: commit (initial): first commit
Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git log
commit a247ad1c5ead23d0554a31c65720e368676beef8 (HEAD -> master)
Author: Li <li@li.com>
Date:   Fri Mar 4 17:08:15 2022 +0800

    first commit

2、修改文件,模拟版本迭代

修改完文件后查看工作区状态:

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ 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:   helloGit.text

no changes added to commit (use "git add" and/or "git commit -a")
Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git commit -m "second commit" helloGit.text
warning: LF will be replaced by CRLF in helloGit.text.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in helloGit.text.
The file will have its original line endings in your working directory
[master 2ea9730] second commit
 1 file changed, 1 insertion(+), 1 deletion(-)

提交完之后再次查看状态:

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git status
On branch master
nothing to commit, working tree clean

查看提交日志:

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git reflog
2ea9730 (HEAD -> master) HEAD@{0}: commit: second commit
a247ad1 HEAD@{1}: commit (initial): first commit

我们可以看到指针指向第二个版本,查看文件:

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ cat helloGit.text
hello git! hello world! 2222222222
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!

再次修改文件:

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git add helloGit.text
warning: LF will be replaced by CRLF in helloGit.text.
The file will have its original line endings in your working directory

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   helloGit.text

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git commit -m "third commit" helloGit.text
warning: LF will be replaced by CRLF in helloGit.text.
The file will have its original line endings in your working directory
[master 6b87440] third commit
 1 file changed, 1 insertion(+), 1 deletion(-)

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git status
On branch master
nothing to commit, working tree clean

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git reflog
6b87440 (HEAD -> master) HEAD@{0}: commit: third commit
2ea9730 HEAD@{1}: commit: second commit
a247ad1 HEAD@{2}: commit (initial): first commit

3、版本穿梭

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git reflog
6b87440 (HEAD -> master) HEAD@{0}: commit: third commit
2ea9730 HEAD@{1}: commit: second commit
a247ad1 HEAD@{2}: commit (initial): first commit

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git reset --hard 2ea9730
HEAD is now at 2ea9730 second commit

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ git reflog
2ea9730 (HEAD -> master) HEAD@{0}: reset: moving to 2ea9730
6b87440 HEAD@{1}: commit: third commit
2ea9730 (HEAD -> master) HEAD@{2}: commit: second commit
a247ad1 HEAD@{3}: commit (initial): first commit

Li@Li-911m MINGW64 /g/work/coding/Git-Space/Java (master)
$ cat helloGit.text
hello git! hello world! 2222222222
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!
hello git! hello world!

版本穿梭会影响工作区的文件!

Git 版本穿梭,底层其实是移动 HEAD 指针:

请添加图片描述


4、Git 分支操作

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2022-03-06 13:19:41  更:2022-03-06 13:21:41 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/26 6:20:04-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码