首页 > 其他分享 >01_初入Git之常用命令

01_初入Git之常用命令

时间:2023-03-14 19:23:25浏览次数:46  
标签:HEAD git 初入 01 master 常用命令 commit txt hello

Git常用命令

在文件夹内右键选择Git Bash Here,可以直接打开Git客户端
代码快捷方式:写出前几个字母然后敲击两次Tab键即可自动补齐代码

命令名称 作用
git config --global user.name 用户名 设置用户签名(新Git仓库必须要执行)
git config --global user.email 用户邮箱 设置用户邮箱(不会验证)
git init 初始化本地库
git status 查看本地库状态
git add 文件名 添加到暂存区
git commit -m "日志信息" 文件名 提交到本地库
git reflog 查看历史记录
git reset -hard 版本 版本穿梭

1)git init(初始化)

$ git init
Initialized empty Git repository in D:/GitSpace/git-demo1/.git/

2)ll(查看)/ll -a(查看隐藏文件)

王杰@wangjie MINGW64 /d/GitSpace/git-demo1 (master)
$ ll
total 0
王杰@wangjie MINGW64 /d/GitSpace/git-demo1 (master)
$ ll -a
total 8
drwxr-xr-x 1 王杰 197121 0 Mar  9 14:57 ./
drwxr-xr-x 1 王杰 197121 0 Mar  9 14:49 ../
drwxr-xr-x 1 王杰 197121 0 Mar  9 14:50 .git/

3)git status(查看状态)

在工作区内的状态颜色为红色,在暂存区内的颜色为绿色

$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
新增hello文件
  1. vim hello.txt
  2. Alt+i进入编辑模式,输入hello
  3. ESC退出编辑模式,yy+p复制粘贴
  4. :wq保存退出
  5. cat hello.txt查看文件内容
  6. tail -r 1 hello.txt 查看最后一行内容
  7. 再次查看:
$ 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)

4)git add(添加暂存区)

$ git add hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it 转化换行符
$ git status
On branch master
No commits yet
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   hello.txt
从暂存区中删除(工作区还存在)
$ git rm --cached hello.txt
rm 'hello.txt'

5)git commit -m "版本" 文件名(提交本地库)

$ git commit -m "first commit" hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
[master (root-commit) 3311fae] first commit
 1 file changed, 10 insertions(+)
 create mode 100644 hello.txt

6)查看版本信息

6.1)git reflog 查看版本精简信息-1
$ git reflog
3311fae (HEAD -> master) HEAD@{0}: commit (initial): first commit
6.2)git log 查看版本详细信息-2
$ git log
commit 3311faef637b68cd032553f60b97dfdab94cac6f (HEAD -> master)
Author: WangJie <[email protected]>
Date:   Thu Mar 9 15:30:17 2023 +0800

    first commit

7)修改文件

7.1)进入文件进行修改

$ vim hello.txt

7.2)修改后使用 git status 查看
$ 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")
7.3)提交到暂存区
$ git add hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
7.4)提交到本地库
$ git commit -m "second commit" hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
[master b88ce29] second commit
 1 file changed, 2 insertions(+), 2 deletions(-)
git的修改是按照行进行的,修改了一行显示为删除一行,新增一行
7.5)查看版本信息
$ git reflog
b88ce29 (HEAD -> master) HEAD@{0}: commit: second commit
指针指向最后修改的版本
3311fae HEAD@{1}: commit (initial): first commit

注意:在git工作区中只会有一个版本的文档,并不是在本地保存多个版本的文档

8)git reset--hard "版本号"(版本穿梭)

原理:修改head->master的指针指向版本,通过修改指针指向的位置,即可实现版本穿梭
每次进行更改版本都会留下记录

王杰@wangjie MINGW64 /d/GitSpace/git-demo1 (master)
$ git reset --hard b88ce29
HEAD is now at b88ce29 second commit
王杰@wangjie MINGW64 /d/GitSpace/git-demo1 (master)
$ git reset --hard 3311fae
HEAD is now at 3311fae first commit
王杰@wangjie MINGW64 /d/GitSpace/git-demo1 (master)
$ git reflog
3311fae (HEAD -> master) HEAD@{0}: reset: moving to 3311fae
b88ce29 HEAD@{1}: reset: moving to b88ce29
b88ce29 HEAD@{2}: commit: second commit
3311fae (HEAD -> master) HEAD@{3}: commit (initial): first commit

标签:HEAD,git,初入,01,master,常用命令,commit,txt,hello
From: https://www.cnblogs.com/wj-goodgoodstudy/p/17198238.html

相关文章

  • Google earth engine——全球森林碳通量(2001-2021)数据集可视化含代码
    全球森林碳通量(2001-2021)森林碳净通量是指2001年至2021年期间森林与大气之间的碳净交换量,计算方法是模型期间森林排放的碳与森林移除(或封存)的碳之间的平衡(兆克CO2排放量/公......
  • 2019 ICPC Asia-East Continent Final
    D考虑树形DP,记\(f[u],g[u]\)分别为最终回到u/停在子树中的最晚第一次到达u的时间。原本以为在枚举了最后一个的情况下,遍历子树的顺序是以f升序的,(因为只有最后一个不对后面......
  • ASEMI低压MOS管SI2301参数,SI2301体积,SI2301尺寸
    编辑-ZASEMI低压MOS管SI2301参数:型号:SI2301漏极-源极电压(VDS):20V栅源电压(VGS):8V漏极电流(ID):2.3A功耗(PD):1.25W储存温度(Tstg):-55to150℃静态漏源导通电阻(RDS(ON)):120mΩ......
  • JavaSE-day01(面向对象高级)
    面向对象的核心:设计对象来处理数据,解决问题。一、静态static读作静态,可以用来修饰成员变量,也能修饰成员方法。1.1static修饰成员变量Java中的成员变量按有无static修......
  • luogu P4566 [CTSC2018]青蕈领主
    题面传送门最后这个转化非常牛逼啊!首先我们可以证明:一个合法的序列中,这样的极长连续区间不会相交。Proof:如果相交了,说明相交的区间也是一段连续区间,而每个区间不相交的......
  • 01trie树相关
    01-trie是指字符集为\(\{0,1\}\)的trie。01-trie可以用来维护一些数字的异或和,支持修改(删除+重新插入),和全局加一(即:让其所维护所有数值递增\(1\),本质上是一种特殊的......
  • ISO9001认证怎么做?ISO9001质量管理体系认证知识科普
    ISO9001认证怎么做?ISO9001质量管理体系认证知识科普ISO体系简介:国际标准化组织(ISO)于1979年成立了质量管理和质量保证技术委员会(TC176),负责制定质量管理和质量保证标准。ISO......
  • iso9001质量体系认证费用详解
    iso9001质量体系认证费用详解现在很多公司都会进行ISO9001质量管理体系认证,ISO9001认证对企业来说是非常重要的,ISO9001质量管理体系认证与企业的未来发展有关,而且会关系到......
  • 自定义DLL显示模式对话框时,控制台显示no message line prompt for id 0xe001的问题。
    在主工程中的资源包里默认为定义应用程序状态栏的准备就绪消息键:#defineAFX_IDS_IDLEMESSAGE0xE001此键在资源包中StringTable中会有对应的文本比如:就绪二字,版权:不......
  • mysql基础知识&&常用命令
    了解什么是数据库?什么是数据管理系统?什么是SQL,他们之间的关系又是什么?数据库英文单词DataBase,简称DB,按照一定格式存储数据的一些文件的组合。顾名思义:存储数据的仓库,实......