私は非常に単純なことをするために頑丈を使用しようとしています:ファイルを作成してコミットし、リポジトリを実行と同じ状態のままにします:
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
私は頑丈なレポのreadmeから改作されたコードを使用しています。
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
と、作業ディレクトリが望ましい状態に戻ります。
助けてくれてありがとう。