1

我使用 Grit/Git 作为数据库来跟踪添加到博客的文件。

我找不到任何关于如何从索引中删除文件的示例。我仍然希望能够在我的 Git 历史记录中拥有该文件(能够通过返回提交历史记录来获取它),但我想将它从我当前的 HEAD 中删除。

任何提示或技巧?

4

2 回答 2

0

http://www.kernel.org/pub/software/scm/git/docs/git-rm.html可能是您需要的。请注意,您需要使用老式的 rm 将其从工作树中删除。

于 2011-03-25T16:09:07.240 回答
0

这应该有效:

  require 'grit'

  repo_path = '/Users/alagu/code/myproject/'
  removable_file = '/Users/alagu/code/myproject/file.txt'
  repo = Grit::Repo.new(repo_path) 
  Dir.chdir(repo_path)
  repo.remove([removable_file])
  repo.commit_index "Deleted #{removable_file}"
于 2013-04-28T17:39:34.620 回答