如何不将特定文件夹推送到远程仓库?

时间:2015-08-10 13:06:30

标签: git

我有一个Ruby on Rails和本地文件的项目,本例中的图像存储在路径/public/system中。我在.gitignore中包含了该行,但每次我将更改推送到远程存储库时,图像都会上传到github。

为什么?

我只是希望这个文件夹及其内容不要上传到github,但我确实希望将这些文件保存在我的本地仓库中。

这是我的.gitignore文件,它只是默认内容,我添加了最后一行:

# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
/tmp

/public/system

1 个答案:

答案 0 :(得分:0)

一旦提交了其中一个文件(请记住git不关心文件夹),将它们添加到.gitignore文件不具有追溯力。您必须使用此命令删除它们

git rm --cached public/system

它只会从git索引中删除它们,而不是在本地修改中删除它们,因此文件夹仍然存在于您的文件系统中。