Skip to content

Commit db6334c

Browse files
committed
update - GIT && fix bugs in utils/update
1 parent 58f3559 commit db6334c

5 files changed

Lines changed: 776 additions & 6 deletions

File tree

source/_posts/GIT 常用命令.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,17 @@ git restore <file>
333333
```shell
334334
git restore --staged <file> # 放弃暂存区
335335
git restore <file> # 放弃工作区
336-
```
336+
```
337+
338+
## git ignore 中新添了 规则
339+
340+
可以直接指定 从暂存区中 remove 从 **版本库** 中移除: 不删除本地文件 (如果没有 --cached 参数 文件也会被删除)
341+
```shell
342+
git rm --cached <example>
343+
```
344+
345+
或者:把所有内容从 版本库 中移除跟踪 重新add
346+
```shell
347+
git rm --cached .
348+
git add .
349+
```

source/bak/GIT 常用命令.md.bak

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ updated: 2025-05-02 04:25:00
55
tags:
66
- GIT
77
- 常用软件
8-
categories: 常用软件
8+
- 终端命令
9+
categories: 终端相关
10+
comments: false
911
---
1012
# 写在前面
1113

@@ -287,4 +289,61 @@ ssh-keygen -t rsa -C "zip95297@gmail.com" # 创建 公私钥 对
287289
√ -> zip @ ~ % ssh -T git@github.com
288290
Hi zip95297! You've successfully authenticated, but GitHub does not provide shell access.
289291
```
290-
配置之后 `git clone` 等 可以用 git 或者 http 连接。
292+
配置之后 `git clone` 等 可以用 git 或者 http 连接。
293+
294+
# 关于从版本库或者工作区中删除
295+
296+
有三个命令主要: clean (清除untracked),restore(删工作区) ,restore --staged (移除暂存区到工作区)
297+
298+
## 删除 !新建!文件 (未跟踪)
299+
300+
clean 是用来删 没被跟踪的 文件和目录 也就是:( 对 已经跟踪 的文件不会有影响)
301+
- 没有被add过
302+
- 在历史提交中没有(untracked)
303+
下面是具体用法
304+
```shell
305+
# 查看哪些文件将被删除(--dry-run|彩排的意思)
306+
git clean -n
307+
308+
# 强制删除
309+
git clean -f
310+
311+
# 删除整个目录目录
312+
git clean -d
313+
314+
# 包括 ignore 的
315+
git clean -x
316+
317+
# 只删除 ignore 的
318+
git clean -X
319+
```
320+
321+
## 恢复到 add 之后的状态 (放弃工作区)
322+
323+
恢复到 add 之后的 也就是:放弃 工作区修改,保留 暂存区修改 (add 过的会保存)
324+
```shell
325+
git restore <file>
326+
```
327+
328+
## 恢复到 上次commit 之后的状态 (放弃工作区和暂存区)
329+
330+
恢复到 上次 commit 之后的状态分为两步:
331+
1. 放弃暂存区
332+
2. 放弃工作区
333+
```shell
334+
git restore --staged <file> # 放弃暂存区
335+
git restore <file> # 放弃工作区
336+
```
337+
338+
## git ignore 中新添了 规则
339+
340+
可以直接指定 从暂存区中 remove 从 **版本库** 中移除: 不删除本地文件 (如果没有 --cached 参数 文件也会被删除)
341+
```shell
342+
git rm --cached <example>
343+
```
344+
345+
或者:把所有内容从 版本库 中移除跟踪 重新add
346+
```shell
347+
git rm --cached .
348+
git add .
349+
```

0 commit comments

Comments
 (0)