• github小记(一):清除github在add或者commit之后缓存区



    前言

    github自用

    一般github上代码提交顺序:

    第一步:

    git add .
    or
    git add home/.../.../file_name
    or
    git add home/.../.../file_name -f
    
    • 1
    • 2
    • 3
    • 4
    • 5

    第二步:

    git commit -m "test..."
    
    • 1

    第三步:

    git push
    
    • 1

    1. 第一步之后想要撤销

    使用git reset .命令

    效果展示:

    xxxxxx@server:~/xxxxxx/test_rm_cache$ git add test/1rrr.txt -f
    xxxxxx@server:~/xxxxxx/test_rm_cache$ git status
    On branch main
    Your branch is up-to-date with 'origin/main'.
    
    Changes to be committed:
      (use "git restore --staged ..." to unstage)
          new file:   test/1rrr.txt
    
    xxxxxx@server:~/xxxxxx/test_rm_cache$ git reset .
    xxxxxx@server:~/xxxxxx/test_rm_cache$ git status
    On branch main
    Your branch is up-to-date with 'origin/main'.
    
    nothing to commit, working tree clean
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    2. 第二步之后想要撤销

    github的内容:
    在这里插入图片描述
    本地文件:
    在这里插入图片描述

    a. 改变一下rrr.txt的内容

    xxxxxx@server:~/xxxxxx/test_rm_cache$ git add .
    xxxxxx@server:~/xxxxxx/test_rm_cache$ git status
    On branch main
    Your branch is up-to-date with 'origin/main'.
    
    Changes to be committed:
      (use "git restore --staged ..." to unstage)
          modified:   rrr.txt
    
    xxxxxx@server:~/xxxxxx/test_rm_cache$ git commit -m "test1"
    [main 6e51030] test1
     1 file changed, 1 insertion(+)
     
    xxxxxx@server:~/xxxxxx/test_rm_cache$ git push
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Delta compression using up to 24 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 244 bytes | 244.00 KiB/s, done.
    Total 3 (delta 1), reused 0 (delta 0)
    remote: Resolving deltas: 100% (1/1), completed with 1 local object.
    To github.com:ZisongXu/test_rm_cache.git
       942633e..6e51030  main -> main
    xxxxxx@server:~/xxxxxx/test_rm_cache$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    github内容:
    在这里插入图片描述
    本地文件:
    在这里插入图片描述

    b. 想提交本地文件的test文件夹

    xxxxxx@server:~/xxxxxx/test_rm_cache$ git add test/1rrr.txt -f
    xxxxxx@server:~/xxxxxx/test_rm_cache$ git status
    On branch main
    Your branch is up-to-date with 'origin/main'.
    
    Changes to be committed:
      (use "git restore --staged ..." to unstage)
          new file:   test/1rrr.txt
    
    xxxxxx@server:~/xxxxxx/test_rm_cache$ git commit -m "test2"
    [main 9375ba3] test2
     1 file changed, 2 insertions(+)
     create mode 100644 test/1rrr.txt
     
    xxxxxx@server:~/xxxxxx/test_rm_cache$ git status
    On branch main
    Your branch is ahead of 'origin/main' by 1 commit.
      (use "git push" to publish your local commits)
    
    nothing to commit, working tree clean
    xxxxxx@server:~/xxxxxx/test_rm_cache$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    c. 我后悔了突然不想提交了

    xxxxxx@server:~/xxxxxx/test_rm_cache$ git reset HEAD~
    xxxxxx@server:~/xxxxxx/test_rm_cache$ git reset --hard HEAD
    HEAD is now at 6e51030 test1
    sc19zx@server:~/apptainers/test_rm_cache$ git status
    On branch main
    Your branch is up-to-date with 'origin/main'.
    
    nothing to commit, working tree clean
    xxxxxx@server:~/xxxxxx/test_rm_cache$ git push
    Everything up-to-date
    xxxxxx@server:~/xxxxxx/test_rm_cache$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    github内容:
    在这里插入图片描述
    本地文件:
    在这里插入图片描述

  • 相关阅读:
    sora生成高质量视频的原理
    MIxformerV2的onnx和tensorrt加速
    2002~2018PJM每小时功率消耗文本数据集(145366行数据,具有明显的季节特性,单位为MW,含LSTM预测程序)
    3.3-3.6二叉树专题
    VIM插件安装与配置
    spring-boot操作elasticsearch
    雪花算法实现
    python利用字典归类列表
    WebSocket快速入门及基本使用
    应广单片机跑马灯实现--阻塞式编程模式
  • 原文地址:https://blog.csdn.net/xzs1210652636/article/details/133710777