2012-04-06 43 views
14

我需要能夠下載我們的應用程序在特定的標籤,但我無法找到一個工作的解決方案。下載基於git標籤的tarball似乎很有前途,但我無法使用Curl使它工作。我已經嘗試了以下,但我回來的是github 404頁面的源代碼。無法從Private Repo下載Git存檔tarball

curl -sL https://github.com/$ACCOUNT/$PRIVATE_REPO/tarball/0.2.0.257m?login=$MY_USER_NAME&token=$MY_TOKEN > 0.2.0.257m.tar 
+0

您是否嘗試過公共回購相同的URL方案? – CharlesB 2012-04-06 16:13:58

+0

你試過wget嗎?或者只是使用git克隆特定標籤的代碼? – 2012-04-06 17:09:24

回答

26

對於公共回購,你有this gist列出一些例子:

wget --no-check-certificate https://github.com/sebastianbergmann/phpunit/tarball/3.5.5 -O ~/tmp/cake_phpunit/phpunit.tgz 

對於私人回購協議,嘗試通過你的證書信息後指令:

wget --quiet --post-data="login=${login}&token=${token}" --no-check-certificate https://github.com/$ACCOUNT/$PRIVATE_REPO/tarball/0.2.0.257m 

或者使用curl命令,如SO問題「git equivalent to svn export or github workaround」,也在很詳細的解釋:
A curl tutorial using GitHub's API」 。


OP Steven Jp報告作出的curl指揮工作:

最後的curl命令結束了看起來像這樣:

curl -sL --user "${username}:${password}" https://github.com/$account/$repo/tarball/$tag_name > tarball.tar 

(多行以便於閱讀)

curl -sL --user "${username}:${password}" 
    https://github.com/$account/$repo/tarball/$tag_name 
    > tarball.tar 
+3

您的第二個鏈接幫助我完成工作。最終的curl命令最終看起來像這樣'curl -sL --user「$ {username}:$ {password}」https://github.com/$account/$repo/tarball/$tag_name> tarball.tar ' – 2012-04-09 17:40:08

+0

@Steven_JP優秀。我已將您的命令包含在答案中,以提高可見性。 – VonC 2012-04-09 17:42:44

+0

感謝您的幫助 – 2012-04-09 18:04:52

11

創建access token後,

您可以使用wget

wget --output-document=<version>.tar.gz \ 
    https://api.github.com/repos/<owner>/<repo>/tarball/<version>?access_token=<OAUTH-TOKEN> 

curl

curl -L https://api.github.com/repos/<owner>/<repo>/tarball/<version>?access_token=<OAUTH-TOKEN> \ 
    > <version>.tar.gz 

更多信息可以在GitHub's API reference for archive links找到。

0

登錄到上Github.com你的私人組織,然後去這裏創建您的令牌: https://github.com/settings/applications#personal-access-tokens

當試圖蜷縮成你的私人組織,使用以下命令:

curl --header 'Authorization: token ADDACCESSTOKENHERE' \ 
--header 'Accept: application/vnd.github.v3.raw' \ 
--remote-name \ 
--location https://api.github.com/repos/ORG/PROJECT/contents/FILE 

更換什麼在大寫與您的信息...

+0

對於一些原因,我有問題與發送多個標頭curl到Github API下載二進制資產,當一個頭是auth。它返回XML響應「僅允許一個授權機制;只應該指定X-Amz算法查詢參數,簽名查詢字符串參數或授權標頭」。但是,如果我將auth從頭部更改爲查詢字符串參數,那麼它可以工作。所以只是提到這個怪癖。 – David 2015-09-22 19:12:14

+0

沒有爲我工作,打印'未找到' – zaitsman 2017-09-14 05:10:01