1

I using Grit/Git as a database to track files added to a blog.

I can't find any example of how I would delete a file from the index. I still want to be able to have the file in my Git history (being able to get it by going back in commit history), but I want to remove it from my current HEAD.

Any tips or tricks?

Ronze
  • 1,544
  • 2
  • 18
  • 33

2 Answers2

0

This should work:

  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}"
Alagu
  • 2,864
  • 3
  • 26
  • 40
0

http://www.kernel.org/pub/software/scm/git/docs/git-rm.html is probably what you need. Note that you'll need to use good old fashioned rm to remove it from the working tree.

jbfink
  • 735
  • 1
  • 7
  • 14