我正在克隆一個具有多個分支的 Github 存盤庫,例如:
root_dir = Dir.mktmpdir(nil, Rails.root.join("repos").to_s)
root_folder = "ruby_git"
Git.clone("https://github.com/ruby-git/ruby-git.git", root_folder, :path => root_dir)
然后我嘗試將分支切換到"test":
g = Git.open(full_dir)
if g.current_branch != "test"
puts g.branch("test").checkout # => "Switched to branch 'test'"
end
分支切換被確認。我什至測驗自己分支是否正確:
puts g.current_branch # => "test"
但是當我最終檢查這樣的檔案時:
puts Dir["#{full_dir}/tests/*"] # => Wrong files that belongs to the default branch...
我看到該檔案夾??仍然包含默認分支的檔案,而不是我切換到的分支。
我做錯了什么,我該如何解決?
uj5u.com熱心網友回復:
自己找到了答案。
我需要拉我切換到的分支:
g.pull("origin", "test")
此處pull參考了該方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/378154.html
