2

私は非常に単純なことをするために頑丈を使用しようとしています:ファイルを作成してコミットし、リポジトリを実行と同じ状態のままにします:

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と、作業ディレクトリが望ましい状態に戻ります。

助けてくれてありがとう。

4

1 に答える 1

4

変更をインデックスに保存するのを忘れました。新しいコミットを指すように参照を更新しましたが、インデックスは変更されていません (決して呼び出さないIndex#writeため)。git に関する限り、ファイルがインデックスにないため、削除がステージングされます。実行しgit rm blah.txtます。

于 2014-07-03T16:20:01.010 に答える