4
我嘗試從Ruby rake任務中執行某些git命令時遇到以下問題(我嘗試過沒有bash --login -c並得到相同的結果)。如何從rake任務中執行git commit/push
tmpid='TueJan26014125UTC2010'
cmd=["git add .",
"git commit -a -m \'Migrate nanoc3 co output to gh-pages #{tmpid}\'",
"git push --force origin gh-pages:gh-pages"
]
FileUtils.chdir @gh_pages_repo_path.to_s do
puts `pwd`
cmd.each do |cmdi|
puts "bash --login -c '#{cmdi}'"
res=Kernel.send(:`, "bash --login -c '#{cmdi}'")
puts res
end
end
我這個輸出顯示工作目錄和混帳推失敗
/home/mv/Documents/Workspaces/scar/ruby/scar/gh-pages
bash --login -c 'git add .'
bash --login -c 'git commit -a -m 'Migrate nanoc3 co output to gh-pages TueJan26014125UTC2010''
# On branch master
nothing to commit (working directory clean)
bash --login -c 'git push --force origin gh-pages:gh-pages'
error: src refspec gh-pages does not match any.
error: failed to push some refs to '[email protected]:hedgehog/scar.git'
To prevent you from losing history, non-fast-forward updates were rejected.
Merge the remote changes before pushing again.
See 'non-fast forward' section of 'git push --help' for details.
如果我運行相同的命令,隨即,從bash shell中(konsole的)所有收益罰款:
$ pushd /home/mv/Documents/Workspaces/scar/ruby/scar/gh-pages
/usr/src ~
$ git add .
$ git commit -a -m 'Migrate nanoc3 co output to gh-pages TueJan26014125UTC2010'
[gh-pages 14cbe34] Migrate nanoc3 co output to gh-pages TueJan26014125UTC2010
20 files changed, 100 insertions(+), 0 deletions(-)
$ git push --force origin gh-pages:gh-pages
Counting objects: 73, done.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (38/38), 11.32 KiB, done.
Total 38 (delta 16), reused 0 (delta 0)
To [email protected]:hedgehog/scar.git
e0f0370..14cbe34 gh-pages -> gh-pages
欣賞任何見解。
不幸的是我也看到了ruby-git的這個錯誤,這也促使我使用shell命令。我還沒有時間來重現這一點,但這似乎已通過運行'git branch -a'和'git remote -v'和'git checkout -track -b gh-pages origin/gh-pages在'git add'之前。之後,上面的腳本工作正常。再一次,還沒有轉載這個......但認爲它與你可以通過Github推薦的建立gh-pages子模塊的方式,即'rm .git/index'等有關。 – Hedgehog 2010-02-01 10:27:55