我正在尝试使用坚固的东西做一些非常简单的事情:创建并提交一个文件,使存储库处于与执行相同的状态:
git init
echo "blah blah blah" > blah.txt
git add blah.txt
git commit -m "write blah.txt"
留下git status
印刷
On branch master
nothing to commit, working directory clean
我正在使用改编自坚固性回购自述文件的代码,归结为:
name = "blah.txt"
repo = Rugged::Repository.init_at dir
File.open File.join(dir, name), 'w' do |f|
f.write content
end
oid = Rugged::Blob.from_workdir repo, name
index = repo.index
index.add(:path => name, :oid => oid, :mode => 0100644)
options = {}
options[:tree] = index.write_tree(repo)
options[:author] = { :email => "testuser@github.com",
:name => 'Test Author',
:time => Time.now }
options[:committer] = { :email => "testuser@github.com",
:name => 'Test Author',
:time => Time.now }
options[:message] = "write #{ name }"
options[:parents] = repo.empty? ? [] : [ repo.head.target ].compact
options[:update_ref] = 'HEAD'
commit = Rugged::Commit.create(repo, options)
这似乎使存储库处于正确的状态,但是工作目录在一个奇怪的地方,带有git status
打印
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: blah.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
blah.txt
我不明白 git 认为此时正在发生什么(blah.txt
准备删除?)。git reset --hard
据我所知,执行将工作目录恢复到所需的状态。
在此先感谢您的帮助。