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

github清除在add或者commit之后缓存区

  • 前言
  • [1. 第一步之后想要撤销](#1. 第一步之后想要撤销)
  • [2. 第二步之后想要撤销](#2. 第二步之后想要撤销)
    • [a. 改变一下rrr.txt的内容](#a. 改变一下rrr.txt的内容)
    • [b. 想提交本地文件的test文件夹](#b. 想提交本地文件的test文件夹)
    • [c. 我后悔了突然不想提交了](#c. 我后悔了突然不想提交了)

前言

github自用

一般github上代码提交顺序:

第一步:

bash 复制代码
git add .
or
git add home/.../.../file_name
or
git add home/.../.../file_name -f

第二步:

bash 复制代码
git commit -m "test..."

第三步:

bash 复制代码
git push

1. 第一步之后想要撤销

使用git reset .命令

效果展示:

bash 复制代码
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 <file>..." 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

2. 第二步之后想要撤销

github的内容:

本地文件:

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

bash 复制代码
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 <file>..." 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$

github内容:

本地文件:

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

bash 复制代码
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 <file>..." 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$

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

bash 复制代码
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$

github内容:

本地文件:

相关推荐
酷酷的崽7982 小时前
Redis 键(Key)的命令
数据库·redis·缓存
逛逛GitHub2 小时前
4 个开源的 yyds 英语学习神器,绝了。
github
程序员鱼皮2 小时前
我看到了 17 年前的 GitHub,竟然长这样?!
程序员·互联网·github·编程·项目
Z_z在努力3 小时前
【杂类】应对 MySQL 处理短时间高并发的请求:缓存预热
数据库·mysql·缓存
lifallen3 小时前
揭秘KafkaStreams 线程缓存:NamedCache深度解析
数据结构·算法·缓存·kafka·apache
失散134 小时前
分布式专题——9 Redis7底层数据结构解析
java·数据结构·redis·分布式·缓存·架构
2501_915921434 小时前
iOS 文件管理与能耗调试结合实战 如何查看缓存文件、优化电池消耗、分析App使用记录(uni-app开发与性能优化必备指南)
android·ios·缓存·小程序·uni-app·iphone·webview
FE_C_P小麦5 小时前
Git 常用指令
前端·后端·github
杨杨杨大侠6 小时前
Atlas Mapper 教程系列 (2/10):环境搭建与项目初始化
java·开源·github