我使用Grit/Git作为数据库来跟踪添加到博客的文件。Grit在提交中删除文件
我找不到如何从索引中删除文件的任何示例。我仍然希望能够在我的Git历史记录中拥有该文件(能够通过恢复提交历史记录来获取该文件),但是我想从当前的HEAD中删除它。
任何提示或技巧?
我使用Grit/Git作为数据库来跟踪添加到博客的文件。Grit在提交中删除文件
我找不到如何从索引中删除文件的任何示例。我仍然希望能够在我的Git历史记录中拥有该文件(能够通过恢复提交历史记录来获取该文件),但是我想从当前的HEAD中删除它。
任何提示或技巧?
http://www.kernel.org/pub/software/scm/git/docs/git-rm.html可能是你需要的。请注意,您需要使用古老的rm将其从工作树中移除。
这应该工作:
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}"
砂粒,不混帐。 Grit是Git的Ruby库。 – 2012-07-27 17:24:55