【Git学习记录】基本命令

  • 初始化

     git init
    
  • 新建一个文件

    vim <file>
    

    eg: vim good.txt

  • 状态查看

    git status
    
  • 当文件夹中无加载内容时候,会出现以下提示:

    $ git status
    starting fsmonitor-daemon in 'D:/学习资料/git'
    error: could not spawn fsmonitor--daemon in the background
    On branch master
    
    No commits yet
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            good.txt
    
    nothing added to commit but untracked files present (use "git add" to track)
    
  • 将工作区的“新建/修改” 添加到暂存区

    git add [file name]
    

    eg: git add good.txt

  • 从暂存区里删除,并没有从文件夹中删除

    *git rm --cached <file>* 
    

    eg: git rm --cached good.txt

  • 暂存区到本地库

    git commit <文件名>
    git commit -m '记录操作的意义' <file>
    

    eg: git commit good.txt 或者 git commit -m 'my second commit,modify' good.txt他俩的区别是是否跳出一个新的vim界面来记录代码相关信息

    如果使用git commit good.txt接着会出现这个界面(可以记录这次操作的意义): 我的这个界面用vscode打开了
    我的界面用vscode打开了,如果想在想将默认编辑器改为vim,可以用下面的命令。

  • git config --global core.editor 'vim'
    就变成了下图:
    在这里插入图片描述
    :set nu可以显示行号
    在这里插入图片描述
    在第一行后面添加一些备注
    在这里插入图片描述
    如果使用git commit -m ‘mysecond…’ good.txt接着会出现这个界面(可以记录这次操作的意义):
    在这里插入图片描述

:wq!退出即可,出现master。。。。就成功了
在这里插入图片描述
上图中7insertions表示good.txt文件添加了7行。可以通过cat 查看,我的里面还有四行空白,所以是七行
在这里插入图片描述
提交到本地库之后的git status:
在这里插入图片描述
如果good.txt文件被修改了查看git status,系统检测到后,有两种解决方法:
1. 重新提交git add <file>或者 git commit <file>
2. 回到之前版本git restore <file>
在这里插入图片描述

  • 查看历史版本
git log
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值