0

我试图在 Heroku 上放置一个新的 Rails 应用程序,并删除了默认索引文件 public/index.html。然而,令我惊讶的是,当我在 Heroku 上访问我的应用程序时,我看到的是默认索引页面,而不是我想要查看的索引。

好的,这有点奇怪,但我想可能有一些原因,比如 Git 没有从存储库中删除文件,即使我删除了它。所以我在网上查了如何强制Git从存储库中删除文件并想出了

git filter-branch --tree-filter 'rm public/index.html' HEAD

但是,当我运行它时,它说“无法用脏工作目录重写分支”。我不确定为什么我的工作目录很脏,因为我刚刚提交,当我运行git status它时说

# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    public/index.html

这让我很困惑,因为我很久以前就删除了 public/index.html。为什么它应该是唯一剩下的变化?尽管如此,我还是跑了git add .git commit -m "..."它说

# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    public/index.html
#
no changes added to commit (use "git add" and/or "git commit -a")

然后,我很生气,尝试git add .git status看到根本没有添加更改。 git add public/index.htmlgit rm public/index.html没有为我做任何事情。然后我用谷歌搜索了这个问题,并想出了一个 StackOverflow 帖子,有人建议尝试git stashgit stash apply刷新。我这样做了,但事情仍然没有奏效。

有什么问题,我该如何解决?

4

2 回答 2

3

我认为你基本上必须提交删除,所以做一个 git commit -a -m '[comment]' 然后它会接受你的删除

于 2012-08-01T00:31:33.027 回答
0

关于 git filter-branch,如果这是您想要的,它将从 repo 中的所有提交中删除该文件。只需在执行之前提交或存储您的更改。如果您只想从现在开始删除它,那么 seansmash 的答案可能就是您所需要的。

于 2012-08-01T00:37:37.780 回答