从Git中删除一个文件夹

时间:2013-01-30 23:43:58

标签: git

我有一个git下的本地文件夹,当我在不同的IDES中玩一些git的东西时,它被添加到git但是我不希望它被git控制,我只是想要它现在是一个普通的文件夹!直到我决定稍后将它添加到某个回购中。

我是git的新手,所以不知道多少命令,但如果我运行git status命令,这就是我得到的:

git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   .idea/vcs.xml
#   new file:   .idea/workspace.xml
#
# 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:   .idea/workspace.xml
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .idea/.name
#   .idea/.rakeTasks
#   .idea/HisFirstService.iml
#   .idea/dictionaries/
#   .idea/encodings.xml
#   .idea/misc.xml
#   .idea/modules.xml
#   .idea/scopes/
#   Gemfile
#   Gemfile.lock
#   README
#   Rakefile
#   client.rb
#   config/
#   db/
#   models/
#   service.rb
#   spec/

5 个答案:

答案 0 :(得分:11)

听起来您想要删除由IDE自动创建的git 存储库。 (请注意,git不会跟踪文件夹,只跟踪文件。)

如果是这种情况,只需删除.git目录,您将留下一个完全没有被git跟踪的文件夹。

答案 1 :(得分:3)

使用git rm --cached从存储库中删除此目录(它应保留在您的工作目录中),然后将其名称放入.gitignore文件中。最后提交.gitignore和目录删除。

答案 2 :(得分:1)

如果您正在使用终端并且有多个要删除的文件要从git中删除,请执行以下操作:

git status | grep [d]eleted | awk '{print $3}' | xargs git rm --cache

答案 3 :(得分:1)

请注意,git不存储目录;它只存储文件。这意味着如果您已将子目录中的任何文件提交到git存储库中,则需要使用git rm <filename>删除它们。您还需要按照git status给出的说明从索引中删除文件。例如,git rm --cached <filename>将删除新文件,因此不会提交它们。最后,您需要创建一个.gitignore文件,其中包含您不希望在repo中拥有的目录的名称。这将使所有未来的git命令都忽略它。

答案 4 :(得分:0)

创建一个名为.gitignore的文件,并添加您要忽略的文件夹的路径(以“/")结尾。

完整文档:https://help.github.com/articles/ignoring-files