GitHub 저장소에서 단일 폴더 또는 디렉토리 다운로드
GitHub에서 호스팅되는 원격 Git 리포지토리에서 특정 폴더 또는 디렉터리 만 다운로드하려면 어떻게해야합니까?
여기에 GitHub 리포지토리가있는 예를 들어 보겠습니다.
git@github.com:foobar/Test.git
디렉토리 구조 :
Test/
foo/
a.py
b.py
bar/
c.py
d.py
전체 테스트 프로젝트를 복제하지 않고 foo 폴더 만 다운로드하고 싶습니다 .
2016 년 9 월 업데이트 :이 작업을 수행 할 수있는 커뮤니티에서 만든 몇 가지 도구가 있습니다.
- GitZip ( Kino에 대한 크레딧 - 여기에서 그의 답변 을 찬성 하세요! )
- DownGit ( Minhas Kamal에 대한 크레딧 - 여기에서 그의 답변에 찬성 투표 하십시오! )
Git은이를 지원하지 않지만 Github는 SVN을 통해 지원합니다. Subversion으로 코드를 체크 아웃하면 Github는 기본적으로 repo를 백엔드의 git에서 subversion으로 변환 한 다음 요청 된 디렉토리를 제공합니다.
이 기능을 사용하여 특정 폴더를 다운로드하는 방법은 다음과 같습니다. 인기있는 자바 스크립트 라이브러리 lodash
를 예로 사용하겠습니다 .
Subversion의 URL을 수정합니다 . 교체
tree/master
와 함께trunk
.https://github.com/lodash/lodash/tree/master/test
➜https://github.com/lodash/lodash/trunk/test
폴더를 다운로드합니다 . 명령 줄로 이동하여 SVN으로 폴더를 가져옵니다.
svn checkout https://github.com/lodash/lodash/trunk/test
Github는 더 큰 저장소를 변환하는 데 최대 30 초가 걸리므로 즉시 활동이 표시되지 않을 수 있으므로 인내심을 가지십시오.
전체 URL 형식 설명 :
master
브랜치에 관심이 있다면trunk
대신 사용하세요. 그래서 전체 경로는trunk/foldername
foo
브랜치에 관심이 있다면branches/foo
대신 사용하세요. 전체 경로는 다음과 같습니다.branches/foo/foldername
- Protip :
svn ls
원하는 경우 다운로드하기 전에 사용 가능한 태그 및 분기를 볼 수 있습니다.
그게 다야! Github 는 변경 사항 커밋 및 푸시 지원을 포함하여 더 많은 하위 버전 기능 도 지원합니다.
이 기능에 대한 두 가지 옵션 :
옵션 1 : 브라우저 확장
용법:
- 모든 GitHub 저장소 페이지에서.
- 필요한 항목의 빈 부분을 두 번 클릭하십시오.
- 오른쪽 하단의 다운로드 버튼을 클릭합니다.
- 진행 대시 보드를보고 브라우저 트리거 다운로드를 기다립니다.
- ZIP 파일을 가져옵니다.
토큰 받기 :
- 브라우저에서 GitZip Extension 아이콘을 클릭합니다.
- "Get Token"옆에있는 "Normal"또는 "Private"링크를 클릭합니다.
- Github 인증 페이지에서 GitZip 권한을 승인합니다.
- 처음의 repo 페이지로 돌아갑니다.
- 계속 사용하십시오.
옵션 2 : Github gh- 페이지
GitHub API 및 JSZip, FileSaver.js 라이브러리를 사용하여 http://kinolien.github.io/gitzip .
1 단계 : 오른쪽 상단의 필드에 github URL을 입력합니다.
2 단계 : Enter 키를 누르거나 다운로드를 클릭하여 zip을 직접 다운로드하거나 검색을 클릭하여 하위 폴더 및 파일 목록을 봅니다.
3 단계 : "Zip 파일 다운로드"또는 "파일 가져 오기"버튼을 클릭하여 파일을 가져옵니다.
대부분의 경우 Github Trees API 제한으로 인해 폴더에 1,000 개 이상의 파일이 포함되어 있다는 점을 제외하고는 정상적으로 작동합니다. ( Github API # Contents 참조 )
또한 GitHub 계정이 있고이 사이트에서 "get token"링크를 사용하면 비공개 / 공용 저장소를 지원하고 속도 제한을 업그레이드 할 수 있습니다.
DownGit > URL 입력> 다운로드로 이동 하십시오!
이제 DownGit 에서 GitHub 공용 디렉토리 또는 파일 ( 특히 대용량 파일 )에 대한 다운로드 링크 를 직접 다운로드 하거나 만들 수 있습니다 ! 다음은 간단한 데모입니다.
다운로드 한 파일의 속성 세부 사용을 구성 할 수도 있습니다 .
이있는 경우 다음 을 수행 svn
하는 svn export
데 사용할 수 있습니다 .
svn export https://github.com/foobar/Test.git/trunk/foo
URL 형식을 확인하십시오.
- 기본 URL은
https://github.com/
/trunk
끝에 추가
를 실행하기 전에 먼저 다음 svn export
을 사용하여 디렉토리의 내용을 확인하는 것이 좋습니다.
svn ls https://github.com/foobar/Test.git/trunk/foo
Generic git Repo의 경우 :
히스토리가있는 저장소를 복제하지 않고 파일을 다운로드하려면 git-archive
.
git-archive
git 저장소의 압축 된 zip 또는 tar 아카이브를 만듭니다. 특별하게 만드는 몇 가지 :
- git 저장소에서 보관할 파일 또는 디렉토리를 선택할 수 있습니다.
.git/
폴더 또는 실행되는 저장소의 추적 되지 않은 파일은 보관하지 않습니다 .- 특정 분기, 태그 또는 커밋을 보관할 수 있습니다. git로 관리되는 프로젝트는 종종 이것을 사용하여 사용자가 다운로드 할 수있는 프로젝트 버전 (베타, 릴리스, 2.0 등)의 아카이브를 생성합니다.
docs/usage
ssh로 연결된 원격 저장소에서 디렉토리 아카이브를 생성하는 예 :
# in terminal
$ git archive --format tar --remote ssh://server.org/path/to/git HEAD docs/usage > /tmp/usage_docs.tar
이 블로그 게시물 과 git 문서 에서 더 많은 정보를 얻을 수 있습니다 .
GitHub Repos에 대한 참고 사항 :
GitHub는 git-archive
액세스를 허용하지 않습니다 . ☹️
GitHubFolderDownloader 라는 오픈 소스 프로젝트를 만들었습니다 . 전체 저장소를 복제하거나 다운로드하지 않고도 저장소의 단일 폴더를 다운로드 할 수 있습니다.
다른 답변에는 문제가 없지만 처음 으로이 프로세스를 방황하는 사람들을 위해 단계별 지침을 공유하겠다고 생각했습니다.
github 저장소에서 단일 폴더를 다운로드하는 방법 (Mac OS X) :
~ 터미널을 열려면 스포트라이트를 클릭하고 터미널을 입력 한 다음 Enter 키를 누르십시오.
- Mac에서는 이미 SVN이있을 수 있습니다 (단지 터미널을 열고 "svn" 또는 "which svn" ~ 따옴표없이 입력).
- Github에서 : 저장소 내에서 특정 폴더 이름을 클릭하여 git 폴더 (repo 아님)의 Github 경로를 찾습니다.
- 브라우저의 주소 표시 줄에서 경로 복사
- 터미널을 열고 다음 을 입력합니다. svn export
- 다음 주소에 붙여 넣으십시오 (예 : https://github.com/mingsai/Sample-Code/tree/master/HeadsUpUI ).
- 단어 바꾸기 : tree / master
- 단어로 : 트렁크
- 파일의 대상 폴더를 입력합니다 (이 예에서는 현재 사용자의 다운로드 폴더 안에 대상 폴더를 저장합니다).
- 여기 공백은 단어 (공백)가 아닌 스페이스 바입니다 ~ / Downloads / HeadsUpUI
- 마지막 터미널 명령은 폴더를 다운로드하는 전체 명령을 보여줍니다 (주소를 5 단계와 비교). svn export https://github.com/mingsai/Sample-Code/trunk/HeadsUpUI ~ / Downloads / HeadsUpUI
BTW-Windows 또는 다른 플랫폼을 사용하는 경우 http://subversion.apache.org 에서 subversion (svn) 바이너리 다운로드를 찾을 수 있습니다 .
~ 단순히 다운로드하는 것보다 폴더를 체크 아웃하려면 svn 도움말을 사용해보십시오 (tldr : export 를 checkout으로 대체 )
최신 정보
중단 된 다운로드 / 체크 아웃 재개에 대한 설명에 대해. 나는 실행하려고 할 것이다 svn cleanup
다음 svn update
. 추가 옵션은 SO를 검색하십시오.
특정 폴더에서 작업하는 사람은 특정 폴더 자체를 복제해야합니다. 이렇게하려면 스파 스 체크 아웃을 사용하여 아래 단계를 따르십시오.
디렉토리를 만듭니다.
Git 저장소를 초기화합니다. (
git init
)Sparse Checkouts를 활성화합니다. (
git config core.sparsecheckout true
)원하는 디렉토리를 Git에게 알려주세요 (echo 2015 / brand / May (작업 할 폴더 참조) >>
.git/info/sparse-checkout
)리모컨 (
git remote add -f origin https://jafartke.com/mkt-imdev/DVM.git
) 추가파일 가져 오기 (
git pull origin master
)
당신은 할 수 없습니다. 각 하위 디렉터리를 개별적으로 체크 아웃 할 수있는 Subversion과 달리 Git은 전체 저장소 기반으로 작동합니다.
세분화 된 액세스가 필요한 프로젝트의 경우 하위 모듈을 사용할 수 있습니다. 각 하위 모듈은 별도의 Git 프로젝트이므로 개별적으로 복제 할 수 있습니다.
It is conceivable that a Git front-end (e.g. GitHub's web interface, or gitweb) could choose to provide an interface for you to extract a given folder, but to my knowledge none of them do that (though they do let you download individual files, so if the folder does not contain too many files, that is an option)
Edit - GitHub actually offers access via SVN, which would allow you to do just this (as per comment). See https://github.com/blog/1438-improved-svn-here-to-stay-old-svn-going-away for latest instructions on how to do this
If you truly just want to just "download" the folder and not "clone" it (for development), the easiest way to simply get a copy of the most recent version of the repository (and therefore a folder/file within it), without needing to clone the whole repo or even install git in the first place, is to download a zip archive (for any repo, fork, branch, commit, etc.) by going to the desired repository/fork/branch/commit on GitHub (e.g. http(s)://github.com/<user>/<repo>/commit/<Sha1>
for a copy of the files as they were after a specific commit) and selecting the Downloads
button near the upper-right.
This archive format contains none of the git-repo magic, just the tracked files themselves (and perhaps a few .gitignore files if they were tracked, but you can ignore those :p) - that means that if the code changes and you want to stay on top, you'll have to manually re-download it, and it also means you won't be able to use it as a git repository...
Not sure if that's what you're looking for in this case (again, "download"/view vs "clone"/develop), but it can be useful nonetheless...
1.Click on this link http://kinolien.github.io/gitzip/
2.Paste link of Github folder you want to download.
3.Click on search it will shows all files for downloading.
Note:-Using search there is no need to enter token key ;)..keep it simple(y)
Another specific example:
Like I want to download 'iOS Pro Geo' folder from the url
https://github.com/alokc83/APRESS-Books-Source-Code-/tree/master/%20Pro%20iOS%20Geo
and I can do so via
svn checkout https://github.com/alokc83/APRESS-Books-Source-Code-/trunk/%20Pro%20iOS%20Geo
Note trunk in the path
Edited: (as per Tommie C's comment)
Yes, using export instead of checkout would give a clean copy without extra git repository files.
svn export https://github.com/alokc83/APRESS-Books-Source-Code-/trunk/%20Pro%20iOS%20Geo
Edited: If tree/master is not there in url then Fork it and it will be there in Forked url.
It's one of the few places where SVN is better than Git.
In the end we've gravitated towards three options:
- Use wget to grab the data from GitHub (using the raw file view).
- Have upstream projects publish the required data subset as build artifacts.
- Give up and use the full checkout. It's big hit on the first build, but unless you get lot of traffic, it's not too much hassle in the following builds.
There's a Python3 pip package called githubdl
that can do this*:
export GIT_TOKEN=1234567890123456789012345678901234567890123
pip install githubdl
githubdl -u http://github.com/foobar/test -d foo
The project page is here
* Disclaimer: I wrote this package.
You can do a simple download of the directory tree:
git archive --remote git@github.com:foobar/Test.git HEAD:foo | tar xf -
But if you mean to check it out, and be able to do commits and push them back, no you can't do that.
If you are comfortable with unix commands, you don't need special dependencies or web apps for this. You can download the repo as a tarball and untar only what you need.
Example (woff2 files from a subdirectory in fontawesome):
curl -L https://api.github.com/repos/FortAwesome/Font-Awesome/tarball | tar xz --wildcards "*/web-fonts-with-css/webfonts/*.woff2" --strip-components=3
- More about the link format: https://developer.github.com/v3/repos/contents/#get-archive-link (including how to get a zip file or specific branches/refs)
- Keep the initial part of the path (
*/
) to match any directory. Github creates a wrapper directory with the commit ref in the name, so it can't be known. - You probably want
--strip-components
to be the same as the amount of slashes (/
) in the path (previous argument).
This will download the whole tarball. Use the SVN method mentioned in the other answers if this has to be avoided or if you want to be nice to the GitHub servers.
Just to amplify the answers above, a real example from a real GitHub repository to a local directory would be:
svn ls https://github.com/rdcarp/playing-cards/trunk/PumpkinSoup.PlayingCards.Interfaces
svn export https://github.com/rdcarp/playing-cards/trunk/PumpkinSoup.PlayingCards.Interfaces /temp/SvnExport/Washburn
Sometimes a concrete example helps clarify the substitutions proposed.
I use linux so , put this in ~/.bashrc , called even :D $HOME/.bashrc
git-dowloadfolder(){
a="$1"
svn checkout ${a/tree\/master/trunk}
}
then refresh the shell with
source ~/.bashrc
then use it with git-downloadfolder blablabla :D
Our team wrote a bash script to do this because we didn't want to have to install SVN on our bare bones server.
https://github.com/ojbc/docker/blob/master/java8-karaf3/files/git-download.sh
It uses the github API and can be run from the command line like this:
git-download.sh https://api.github.com/repos/ojbc/main/contents/shared/ojb-certs
I work with CentOS 7 servers on which I don't have root access, nor git, svn, etc (nor want to!) so made a python script to download any github folder: https://github.com/andrrrl/github-folder-downloader
Usage is simple, just copy the relevant part from a github project, let's say the project is https://github.com/MaxCDN/php-maxcdn/, and you want a folder where some source files are only, then you need to do something like:
$ python gdownload.py "/MaxCDN/php-maxcdn/tree/master/src" /my/target/dir/
(will create target folder if doesn't exist)
It requires lxml library, can be installed with easy_install lxml
If you don't have root access (like me) you can create a .pydistutils.py
file into your $HOME
dir with these contents: [install] user=1
And easy_install lxml
will just work (ref: https://stackoverflow.com/a/33464597/591257).
None of the answers helped in my situation. If you are developing for Windows, you likely don't have svn. In many situations one can't count on users to have Git installed either, or don't want to download entire repositories for other reasons. Some of the people that answered this question, such as Willem van Ketwich and aztack, made tools to accomplish this task. However, if the tool isn't written for the language you are using, or you don't want to install a third party library, these don't work.
However, there is a much easier way. GitHub has an API that allows you to download a single file or an entire directory's contents using GET requests. You can access a directory using https://api.github.com/repos/:owner/:repo_name/contents/:path
that returns a JSON object enumerating all the files in the directory. Included in the enumeration is a link to the raw content of the file, the download_url
parameter. The file can then be downloaded using that URL.
It's a two step process that requires the ability to make GET requests, but this can be implemented in pretty much any language, on any platform. It can be used to get files or directories.
To export a directory from GitHub, replace "/tree/master/" in the directory's url with "/trunk/".
For example, to export the directory from the following URL:
https://github.com/liferay/liferay-plugins/tree/master/portlets/sample-hibernate-portlet
run the following command:
svn export https://github.com/liferay/liferay-plugins/trunk/portlets/sample-hibernate-portlet
If you need to do it programatically and you don't want to rely on SVN, you can use GitHub API to download all the contents recursively.
For inspiration, here's my ruby gist: https://gist.github.com/cvengros/b2a7e82f66519d423b6f
Use this function, the first argument is the url to the folder, the second is the place the folder will be downloaded to:
function github-dir() {
svn export "$(sed 's/tree\/master/trunk/' <<< "$1")" "$2"
}
A straightforward answer to this is to first tortoise svn from following link.
while installation turn on CLI option, so that it can be used from command line interface.
copy the git hub sub directory link.
Example
https://github.com/tensorflow/models/tree/master/research/deeplab
replace tree/master with trunk
and do
svn checkout https://github.com/tensorflow/models/trunk/research/deeplab
files will be downloaded to the deeplab folder in the current directory.
git clone --filter
from Git 2.19
This option will actually skip fetching unneeded objects from the server:
git clone --depth 1 --no-checkout --filter=blob:none \
"file://$(pwd)/server_repo" local_repo
cd local_repo
git checkout master -- mydir/
The server should be configured with:
git config --local uploadpack.allowfilter 1
git config --local uploadpack.allowanysha1inwant 1
An extension was made to the Git remote protocol to support this feature in v2.19.0, but there is no server support at that time. But it can already be locally tested.
I have covered this in more detail at: How do I clone a subdirectory only of a Git repository?
If you want to use Python and SVN to download a specific GitHub directory, here is the code that you would use:
import validators
from svn.remote import RemoteClient
def download_folder(url):
if 'tree/master' in url:
url = url.replace('tree/master', 'trunk')
r = RemoteClient(url)
r.export('output')
if __name__ == '__main__':
url = input('Enter folder URL: ')
if not validators.url(url):
print('Invalid url')
else:
download_folder(url)
You can check more details about this code and other GitHub search and download tips in this tutorial: https://python.gotrained.com/search-github-api/
다운로드하려는 디렉토리가 별도의 라이브러리 인 경우 다른 git repo를 만든 다음 git 하위 모듈 기능을 사용하는 것이 좋습니다.
물론 원하는 초기 저장소의 소유자 여야합니다.
참고 URL : https://stackoverflow.com/questions/7106012/download-a-single-folder-or-directory-from-a-github-repo
'program tip' 카테고리의 다른 글
jQuery 데이터 속성 값을 기반으로 요소를 찾는 방법은 무엇입니까? (0) | 2020.09.28 |
---|---|
원격에서 더 이상 추적 분기 제거 (0) | 2020.09.28 |
RecyclerView에 onItemClickListener ()가없는 이유는 무엇입니까? (0) | 2020.09.28 |
로컬 디렉터리에서 requirements.txt 파일에 따라 pip를 사용하여 패키지를 설치하는 방법은 무엇입니까? (0) | 2020.09.28 |
Node.js를 사용하여 JSON을 구문 분석하는 방법은 무엇입니까? (0) | 2020.09.28 |