最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]删除已经git add了但是还没有push提交的文件夹

Git crifan 3211浏览 0评论

折腾git期间,不小心add了一个不需要add的文件夹

现在想要去删除。

自己去折腾,最终通过:

git rm -rf flask

其中:

r表示recursive,递归删除flask(文件夹)及其下的文件

f表示force,否则由于是(刚刚git add了,但是)还没有提交,所以要强制才能删除

即可删除掉:

当前git add了但是还没有push的文件。

详细的log如下:

自己help看看,有哪些命令:

➜  sipevents git:(master) git help
usage: git [–version] [–help] [-C <path>] [-c name=value]
           [–exec-path[=<path>]] [–html-path] [–man-path] [–info-path]
           [-p | –paginate | –no-pager] [–no-replace-objects] [–bare]
           [–git-dir=<path>] [–work-tree=<path>] [–namespace=<name>]
           <command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
   clone      Clone a repository into a new directory
   init       Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
   add        Add file contents to the index
   mv         Move or rename a file, a directory, or a symlink
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
   bisect     Use binary search to find the commit that introduced a bug
   grep       Print lines matching a pattern
   log        Show commit logs
   show       Show various types of objects
   status     Show the working tree status
grow, mark and tweak your common history
   branch     List, create, or delete branches
   checkout   Switch branches or restore working tree files
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   merge      Join two or more development histories together
   rebase     Forward-port local commits to the updated upstream head
   tag        Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
   fetch      Download objects and refs from another repository
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects
‘git help -a’ and ‘git help -g’ list available subcommands and some
concept guides. See ‘git help <command>’ or ‘git help <concept>’
to read about a specific subcommand or concept.

然后自己去试试rm,结果删除不了,提示出错:

➜  sipevents git:(master) git rm flask/*
fatal: not removing ‘flask/ext’ recursively without -r
➜  sipevents git:(master) git rm flask
fatal: not removing ‘flask’ recursively without -r

根据提示,去加上-r参数:

➜  sipevents git:(master) git rm -r flask
error: the following files have changes staged in the index:
    flask/__init__.py
    flask/__main__.py
    flask/_compat.py
    flask/app.py
    flask/blueprints.py
    flask/cli.py
    flask/config.py
    flask/ctx.py
    flask/debughelpers.py
    flask/ext/__init__.py
    flask/exthook.py
    flask/globals.py
    flask/helpers.py
    flask/json.py
    flask/logging.py
    flask/sessions.py
    flask/signals.py
    flask/templating.py
    flask/testing.py
    flask/views.py
    flask/wrappers.py
(use –cached to keep the file, or -f to force removal)

结果去看看,文件夹和文件还是没有删掉:

➜  sipevents git:(master) git status
On branch master
Your branch is up-to-date with ‘origin/master’.
Changes to be committed:
  (use “git reset HEAD <file>…” to unstage)
new file:   config.py
new file:   db_create.py
new file:   db_manager.py
new file:   flask/__init__.py
new file:   flask/__main__.py
new file:   flask/_compat.py
new file:   flask/app.py
new file:   flask/blueprints.py
new file:   flask/cli.py
new file:   flask/config.py
new file:   flask/ctx.py
new file:   flask/debughelpers.py
new file:   flask/ext/__init__.py
new file:   flask/exthook.py
new file:   flask/globals.py
new file:   flask/helpers.py
new file:   flask/json.py
new file:   flask/logging.py
new file:   flask/sessions.py
new file:   flask/signals.py
new file:   flask/templating.py
new file:   flask/testing.py
new file:   flask/views.py
new file:   flask/wrappers.py
new file:   instance/config.py
new file:   run.py
new file:   sipevents/__init__.py
new file:   sipevents/forms.py
new file:   sipevents/models.py
new file:   sipevents/static/css/datetimepicker/jquery.datetimepicker.css
new file:   sipevents/static/css/datetimepicker/jquery.datetimepicker.min.css
new file:   sipevents/static/css/framework7.ios.colors.css
new file:   sipevents/static/css/framework7.ios.colors.min.css
new file:   sipevents/static/css/framework7.ios.css
new file:   sipevents/static/css/framework7.ios.min.css
new file:   sipevents/static/css/framework7.ios.rtl.css
new file:   sipevents/static/css/framework7.ios.rtl.min.css
new file:   sipevents/static/css/framework7.material.colors.css
new file:   sipevents/static/css/framework7.material.colors.min.css
new file:   sipevents/static/css/framework7.material.css
new file:   sipevents/static/css/framework7.material.min.css
new file:   sipevents/static/css/framework7.material.rtl.css
new file:   sipevents/static/css/framework7.material.rtl.min.css
new file:   sipevents/static/css/my-app.css
new file:   sipevents/static/img/avatar/limao.jpg
new file:   sipevents/static/img/avatar/liyuanfei.jpg
new file:   sipevents/static/img/avatar/navi_add_lightblue_24x24.svg
new file:   sipevents/static/img/avatar/oswjmv02FBc16eCjUsJY3tOEj_wo.png
new file:   sipevents/static/img/avatar/oswjmv4X0cCXcfkIwjoDfCkeTVVY.png
new file:   sipevents/static/img/avatar/oswjmv6AxX5vOgtlsYL8qiPFyB1Q.png
new file:   sipevents/static/img/avatar/oswjmv7kEyDhFfYLQCbJHTlnXdow.png
new file:   sipevents/static/img/avatar/oswjmvw7lf73HT53QHOWwl4-pKr8.png
new file:   sipevents/static/img/avatar/wutao.jpg
new file:   sipevents/static/img/avatar/zhangbinglian.jpg
new file:   sipevents/static/img/avatar/zhouhaixiao.jpg
new file:   sipevents/static/img/i-f7-ios.png
new file:   sipevents/static/img/i-f7-material.png
new file:   sipevents/static/img/i-form-calendar-ios.svg
new file:   sipevents/static/img/i-form-calendar-material.svg
new file:   sipevents/static/img/i-form-comment-ios.svg
new file:   sipevents/static/img/i-form-comment-material.svg
new file:   sipevents/static/img/i-form-email-ios.svg
new file:   sipevents/static/img/i-form-email-material.svg
new file:   sipevents/static/img/i-form-gender-ios.svg
new file:   sipevents/static/img/i-form-gender-material.svg
new file:   sipevents/static/img/i-form-name-ios.svg
new file:   sipevents/static/img/i-form-name-material.svg
new file:   sipevents/static/img/i-form-password-ios.svg
new file:   sipevents/static/img/i-form-password-material.svg
new file:   sipevents/static/img/i-form-settings-ios.svg
new file:   sipevents/static/img/i-form-settings-material.svg
new file:   sipevents/static/img/i-form-tel-ios.svg
new file:   sipevents/static/img/i-form-tel-material.svg
new file:   sipevents/static/img/i-form-toggle-ios.svg
new file:   sipevents/static/img/i-form-toggle-material.svg
new file:   sipevents/static/img/i-form-url-ios.svg
new file:   sipevents/static/img/i-form-url-material.svg
new file:   sipevents/static/js/datetimepicker/jquery.datetimepicker.full.js
new file:   sipevents/static/js/datetimepicker/jquery.datetimepicker.full.min.js
new file:   sipevents/static/js/datetimepicker/jquery.datetimepicker.js
new file:   sipevents/static/js/datetimepicker/jquery.js
new file:   sipevents/static/js/framework7.js
new file:   sipevents/static/js/framework7.js.map
new file:   sipevents/static/js/framework7.min.js
new file:   sipevents/static/js/framework7.min.js.map
new file:   sipevents/static/js/my-app.js
new file:   sipevents/templates/creatEvent.html
new file:   sipevents/templates/index.html
new file:   sipevents/templates/showEvent.html
new file:   sipevents/views.py
Changes not staged for commit:
  (use “git add <file>…” to update what will be committed)
  (use “git checkout — <file>…” to discard changes in working directory)
modified:   .gitignore

注意到前面的提示,去加上-f试试:

然后发现就可以删除掉了:

➜  sipevents git:(master) git rm -rf flask
rm ‘flask/__init__.py’
rm ‘flask/__main__.py’
rm ‘flask/_compat.py’
rm ‘flask/app.py’
rm ‘flask/blueprints.py’
rm ‘flask/cli.py’
rm ‘flask/config.py’
rm ‘flask/ctx.py’
rm ‘flask/debughelpers.py’
rm ‘flask/ext/__init__.py’
rm ‘flask/exthook.py’
rm ‘flask/globals.py’
rm ‘flask/helpers.py’
rm ‘flask/json.py’
rm ‘flask/logging.py’
rm ‘flask/sessions.py’
rm ‘flask/signals.py’
rm ‘flask/templating.py’
rm ‘flask/testing.py’
rm ‘flask/views.py’
rm ‘flask/wrappers.py’
➜  sipevents git:(master) git status     
On branch master
Your branch is up-to-date with ‘origin/master’.
Changes to be committed:
  (use “git reset HEAD <file>…” to unstage)
new file:   config.py
new file:   db_create.py
new file:   db_manager.py
new file:   instance/config.py
new file:   run.py
new file:   sipevents/__init__.py
new file:   sipevents/forms.py
new file:   sipevents/models.py
new file:   sipevents/static/css/datetimepicker/jquery.datetimepicker.css
new file:   sipevents/static/css/datetimepicker/jquery.datetimepicker.min.css
new file:   sipevents/static/css/framework7.ios.colors.css
new file:   sipevents/static/css/framework7.ios.colors.min.css
new file:   sipevents/static/css/framework7.ios.css
new file:   sipevents/static/css/framework7.ios.min.css
new file:   sipevents/static/css/framework7.ios.rtl.css
new file:   sipevents/static/css/framework7.ios.rtl.min.css
new file:   sipevents/static/css/framework7.material.colors.css
new file:   sipevents/static/css/framework7.material.colors.min.css
new file:   sipevents/static/css/framework7.material.css
new file:   sipevents/static/css/framework7.material.min.css
new file:   sipevents/static/css/framework7.material.rtl.css
new file:   sipevents/static/css/framework7.material.rtl.min.css
new file:   sipevents/static/css/my-app.css
new file:   sipevents/static/img/avatar/limao.jpg
new file:   sipevents/static/img/avatar/liyuanfei.jpg
new file:   sipevents/static/img/avatar/navi_add_lightblue_24x24.svg
new file:   sipevents/static/img/avatar/oswjmv02FBc16eCjUsJY3tOEj_wo.png
new file:   sipevents/static/img/avatar/oswjmv4X0cCXcfkIwjoDfCkeTVVY.png
new file:   sipevents/static/img/avatar/oswjmv6AxX5vOgtlsYL8qiPFyB1Q.png
new file:   sipevents/static/img/avatar/oswjmv7kEyDhFfYLQCbJHTlnXdow.png
new file:   sipevents/static/img/avatar/oswjmvw7lf73HT53QHOWwl4-pKr8.png
new file:   sipevents/static/img/avatar/wutao.jpg
new file:   sipevents/static/img/avatar/zhangbinglian.jpg
new file:   sipevents/static/img/avatar/zhouhaixiao.jpg
new file:   sipevents/static/img/i-f7-ios.png
new file:   sipevents/static/img/i-f7-material.png
new file:   sipevents/static/img/i-form-calendar-ios.svg
new file:   sipevents/static/img/i-form-calendar-material.svg
new file:   sipevents/static/img/i-form-comment-ios.svg
new file:   sipevents/static/img/i-form-comment-material.svg
new file:   sipevents/static/img/i-form-email-ios.svg
new file:   sipevents/static/img/i-form-email-material.svg
new file:   sipevents/static/img/i-form-gender-ios.svg
new file:   sipevents/static/img/i-form-gender-material.svg
new file:   sipevents/static/img/i-form-name-ios.svg
new file:   sipevents/static/img/i-form-name-material.svg
new file:   sipevents/static/img/i-form-password-ios.svg
new file:   sipevents/static/img/i-form-password-material.svg
new file:   sipevents/static/img/i-form-settings-ios.svg
new file:   sipevents/static/img/i-form-settings-material.svg
new file:   sipevents/static/img/i-form-tel-ios.svg
new file:   sipevents/static/img/i-form-tel-material.svg
new file:   sipevents/static/img/i-form-toggle-ios.svg
new file:   sipevents/static/img/i-form-toggle-material.svg
new file:   sipevents/static/img/i-form-url-ios.svg
new file:   sipevents/static/img/i-form-url-material.svg
new file:   sipevents/static/js/datetimepicker/jquery.datetimepicker.full.js
new file:   sipevents/static/js/datetimepicker/jquery.datetimepicker.full.min.js
new file:   sipevents/static/js/datetimepicker/jquery.datetimepicker.js
new file:   sipevents/static/js/datetimepicker/jquery.js
new file:   sipevents/static/js/framework7.js
new file:   sipevents/static/js/framework7.js.map
new file:   sipevents/static/js/framework7.min.js
new file:   sipevents/static/js/framework7.min.js.map
new file:   sipevents/static/js/my-app.js
new file:   sipevents/templates/creatEvent.html
new file:   sipevents/templates/index.html
new file:   sipevents/templates/showEvent.html
new file:   sipevents/views.py
Changes not staged for commit:
  (use “git add <file>…” to update what will be committed)
  (use “git checkout — <file>…” to discard changes in working directory)
modified:   .gitignore
➜  sipevents git:(master)

[后记]

但是郁闷了:

此处,以为是从git的add的临时内容中删除了flask文件夹,

但是会从物理上删除对应的文件:

-》

所以,幸好此处我有备份,否则还会误删文件呢。。。

再拷贝过来一份flask文件夹

然后再去更新.gitignore

# PyCharm
# http://www.jetbrains.com/pycharm/webhelp/project.html
.idea
.iml
# Mac
.DS_Store
# external PyCharm lib
flask/
wechat_sdk/
wechat-python-sdk

再去看看status:

➜  sipevents git:(master) ll
total 48
-rw-r–r–   1 crifan  staff    12B  9  2 14:49 README.md
-rw-r–r–   1 crifan  staff   436B  8 25 16:47 config.py
-rw-r–r–   1 crifan  staff   6.7K  8 30 17:53 db_create.py
-rw-r–r–   1 crifan  staff   773B  8 29 17:57 db_manager.py
drwxr-xr-x@ 23 crifan  staff   782B  8 23 14:48 flask
drwxr-xr-x   3 crifan  staff   102B  8 29 17:53 instance
-rw-r–r–   1 crifan  staff    77B  8 23 14:39 run.py
drwxr-xr-x   8 crifan  staff   272B  9  2 10:29 sipevents
drwxr-xr-x@ 15 crifan  staff   510B  8 21 10:46 wechat-python-sdk
drwxr-xr-x@ 13 crifan  staff   442B  8 21 17:03 wechat_sdk
➜  sipevents git:(master) git status
On branch master
Your branch is up-to-date with ‘origin/master’.
Changes to be committed:
  (use “git reset HEAD <file>…” to unstage)
new file:   config.py
new file:   db_create.py
new file:   db_manager.py
new file:   instance/config.py
new file:   run.py
new file:   sipevents/__init__.py
new file:   sipevents/forms.py
new file:   sipevents/models.py
new file:   sipevents/static/css/datetimepicker/jquery.datetimepicker.css
new file:   sipevents/static/css/datetimepicker/jquery.datetimepicker.min.css
new file:   sipevents/static/css/framework7.ios.colors.css
new file:   sipevents/static/css/framework7.ios.colors.min.css
new file:   sipevents/static/css/framework7.ios.css
new file:   sipevents/static/css/framework7.ios.min.css
new file:   sipevents/static/css/framework7.ios.rtl.css
new file:   sipevents/static/css/framework7.ios.rtl.min.css
new file:   sipevents/static/css/framework7.material.colors.css
new file:   sipevents/static/css/framework7.material.colors.min.css
new file:   sipevents/static/css/framework7.material.css
new file:   sipevents/static/css/framework7.material.min.css
new file:   sipevents/static/css/framework7.material.rtl.css
new file:   sipevents/static/css/framework7.material.rtl.min.css
new file:   sipevents/static/css/my-app.css
new file:   sipevents/static/img/avatar/limao.jpg
new file:   sipevents/static/img/avatar/liyuanfei.jpg
new file:   sipevents/static/img/avatar/navi_add_lightblue_24x24.svg
new file:   sipevents/static/img/avatar/oswjmv02FBc16eCjUsJY3tOEj_wo.png
new file:   sipevents/static/img/avatar/oswjmv4X0cCXcfkIwjoDfCkeTVVY.png
new file:   sipevents/static/img/avatar/oswjmv6AxX5vOgtlsYL8qiPFyB1Q.png
new file:   sipevents/static/img/avatar/oswjmv7kEyDhFfYLQCbJHTlnXdow.png
new file:   sipevents/static/img/avatar/oswjmvw7lf73HT53QHOWwl4-pKr8.png
new file:   sipevents/static/img/avatar/wutao.jpg
new file:   sipevents/static/img/avatar/zhangbinglian.jpg
new file:   sipevents/static/img/avatar/zhouhaixiao.jpg
new file:   sipevents/static/img/i-f7-ios.png
new file:   sipevents/static/img/i-f7-material.png
new file:   sipevents/static/img/i-form-calendar-ios.svg
new file:   sipevents/static/img/i-form-calendar-material.svg
new file:   sipevents/static/img/i-form-comment-ios.svg
new file:   sipevents/static/img/i-form-comment-material.svg
new file:   sipevents/static/img/i-form-email-ios.svg
new file:   sipevents/static/img/i-form-email-material.svg
new file:   sipevents/static/img/i-form-gender-ios.svg
new file:   sipevents/static/img/i-form-gender-material.svg
new file:   sipevents/static/img/i-form-name-ios.svg
new file:   sipevents/static/img/i-form-name-material.svg
new file:   sipevents/static/img/i-form-password-ios.svg
new file:   sipevents/static/img/i-form-password-material.svg
new file:   sipevents/static/img/i-form-settings-ios.svg
new file:   sipevents/static/img/i-form-settings-material.svg
new file:   sipevents/static/img/i-form-tel-ios.svg
new file:   sipevents/static/img/i-form-tel-material.svg
new file:   sipevents/static/img/i-form-toggle-ios.svg
new file:   sipevents/static/img/i-form-toggle-material.svg
new file:   sipevents/static/img/i-form-url-ios.svg
new file:   sipevents/static/img/i-form-url-material.svg
new file:   sipevents/static/js/datetimepicker/jquery.datetimepicker.full.js
new file:   sipevents/static/js/datetimepicker/jquery.datetimepicker.full.min.js
new file:   sipevents/static/js/datetimepicker/jquery.datetimepicker.js
new file:   sipevents/static/js/datetimepicker/jquery.js
new file:   sipevents/static/js/framework7.js
new file:   sipevents/static/js/framework7.js.map
new file:   sipevents/static/js/framework7.min.js
new file:   sipevents/static/js/framework7.min.js.map
new file:   sipevents/static/js/my-app.js
new file:   sipevents/templates/creatEvent.html
new file:   sipevents/templates/index.html
new file:   sipevents/templates/showEvent.html
new file:   sipevents/views.py
Changes not staged for commit:
  (use “git add <file>…” to update what will be committed)
  (use “git checkout — <file>…” to discard changes in working directory)
modified:   .gitignore

就可以实现了之前需要的:

存在flask文件夹,但是不加入git

转载请注明:在路上 » [已解决]删除已经git add了但是还没有push提交的文件夹

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.172 seconds, using 22.17MB memory