撤销git add操作

简介: 使用Git的时候,有时候不小心使用git add,添加了不想追踪的文件。也就是track了一些不想track的文件,这个时候需要撤销操作,怎么处理呢?Git 文件状态的生命周期演示还原操作使用git reset命令...

使用Git的时候,有时候不小心使用git add,添加了不想追踪的文件。也就是track了一些不想track的文件,这个时候需要撤销操作,怎么处理呢?

img_99b9caf28b7327eb91f276c8666647cd.png
Git 文件状态的生命周期

演示

img_bc817a26da9964c74120769205e879ac.png
还原操作
  1. 使用git reset命令


    img_f51defb335345566704ce3d83390aa33.png
    git set命令效果
  2. 使用git rm --cached [filename]命令


    img_d3dc497c49489b8856516c885f43bcbd.png
    git rm命令效果

git rm
--cached
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.

额外

在文件未被git track的时候,可以添加.gitignore文件,来指定不想追踪那些文件。


img_3d10a702ea03b33251fd16b150c3e1bd.png
gitignore的效果

最后

简单的介绍了git的一些基本功能

目录
打赏
0
0
0
0
1130
分享
相关文章
记IDEA Git版本回退并push到远程操作
记IDEA Git版本回退并push到远程操作
278 1
记IDEA Git版本回退并push到远程操作
warning: You ran ‘git add’ with neither ‘-A (—all)’ or ‘—ignore-removal’,报错如何解决 git报错 ‘git add —ignore-removal <pathspec>优雅草卓伊凡
warning: You ran ‘git add’ with neither ‘-A (—all)’ or ‘—ignore-removal’,报错如何解决 git报错 ‘git add —ignore-removal <pathspec>优雅草卓伊凡
77 21
warning: You ran ‘git add’ with neither ‘-A (—all)’ or ‘—ignore-removal’,报错如何解决 git报错 ‘git add —ignore-removal <pathspec>优雅草卓伊凡
蓝易云 - git中,add到暂存区,commit且push之后,暂存区域里还有内容吗
所以,当你执行 `git add`,然后是 `git commit`,最后是 `git push`之后,暂存区是空的,除非你又执行了新的 `git add`命令来添加更多的更改。
103 1
idea的git reset current branch to here操作详解
idea的git reset current branch to here操作详解
1218 1
git 超实用教程【人人必会!】(含大厂的 git 操作规范)
git 超实用教程【人人必会!】(含大厂的 git 操作规范)
250 0
【专栏】探讨了 Git 中的 `git rebase` 操作,它用于重新应用提交到另一分支,改变历史顺序
【4月更文挑战第29天】本文探讨了 Git 中的 `git rebase` 操作,它用于重新应用提交到另一分支,改变历史顺序。与 `git merge` 不同,rebase 重写提交历史,提供简洁线性的历史记录。文章介绍了 rebase 的基本操作、应用场景,如整理提交历史、解决冲突和整合分支,并强调了使用注意事项,如避免在公共分支上操作。尽管 rebase 可以带来整洁的历史和冲突解决便利,但其潜在的风险和可能导致的历史混乱需谨慎对待。理解并恰当使用 `git rebase` 可以提升开发效率和代码质量。
398 1
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等