Git의 서버 저장소에서 단일 파일을 가져 오는 방법은 무엇입니까?
Git을 실행하는 서버가있는 사이트에서 작업 중입니다. 배포를 위해 Git을 사용하고 있습니다 (GitHub가 아님). 이것은 연결 방법을 사용하여 참여하기 전에 설정 되었으며이 질문을 참조하고 아래 명령을 입력했지만 작동하지 않았습니다.
서버에서 단일 파일을 어떻게 가져 옵니까? 예를 들어, 내 로컬 파일 index.php를 업데이트하고 싶다면? git pull index.php
?
다음을 수행 할 수 있습니다 (배포 된 저장소에서).
git fetch
// git fetch will download all the recent changes, but it will not put it in your current checked out code (working area).
뒤에 :
git checkout origin/master -- path/to/file
// git checkout <local repo name (default is origin)>/<branch name> -- path/to/file will checkout the particular file from the downloaded changes (origin/master).
git fetch --all
git checkout origin/master -- <your_file_path>
git add <your_file_path>
git commit -m "<your_file_name> updated"
이것은 원본 / 마스터에서 파일을 가져오고 있다고 가정합니다.
이것이 해결책이 될 수 있습니다.
git fetch
git checkout origin/master -- FolderPathName/fileName
감사.
이 시나리오는 로컬 저장소에서 파일 을 엉망으로 만들고 저장소에서 최신 버전의 새 복사본을 복원하려는 경우에 발생합니다. / bin / rm (git rm이 아님)으로 파일을 삭제하거나 이름을 바꾸거나 숨긴 다음 a를 실행하는 git pull
것은 작동하지 않습니다. git은 파일이 없음을 확인하고 repo git diff
에서 삭제하기를 원한다고 가정합니다 ( 누락 된 파일).
git pull
로컬에서 누락 된 파일을 복원하지 않는 것은 아마도 다른 버전 제어 시스템 (예 : 로컬에 숨겨진 파일을 복원 할 것이라고 생각하는 svn 업데이트)의 영향을 받았기 때문에 git에 대해 항상 실망했습니다 .
git reset --hard HEAD
커밋되지 않은 변경 사항을 제거하므로 관심있는 파일을 복원하는 다른 방법입니다. 그러나 여기 에서 언급했듯이 git reset은 다른 커밋되지 않은 변경 사항이있는 경우 잠재적으로 위험한 명령입니다.
git fetch ... git checkout
@chrismillah에 의해 위에서 언급 전략은 문제의 파일을 복원 할 수있는 좋은 수술 방법입니다.
https://raw.githubusercontent.com/[USER-NAME]/[REPOSITORY-NAME]/[BRANCH-NAME]/[FILE-PATH]
전의. https://raw.githubusercontent.com/vipinbihari/apana-result/master/index.php
이를 통해 개별 파일의 내용을 행 텍스트로 얻을 수 있습니다. wget으로 해당 텍스트를 다운로드 할 수 있습니다.
전의. https://raw.githubusercontent.com/vipinbihari/apana-result/master/index.php
다음을 사용해보십시오.
git checkout branchName -- fileName
전의:
git checkout master -- index.php
이 Windows 배치는 GitHub에 있는지 여부에 관계없이 작동합니다. 나는 그것을 사용하고 있습니다. 작업이 느리고 수백 메가 바이트의 데이터를 순회한다는 것을 알 수 있으므로 요구 사항이 사용 가능한 대역폭 / RW 메모리를 기반으로하는 경우이 방법을 사용하지 마십시오.
sparse_checkout.bat
pushd "%~dp0"
if not exist .\ms-server-essentials-docs mkdir .\ms-server-essentials-docs
pushd .\ms-server-essentials-docs
git init
git remote add origin -f https://github.com/MicrosoftDocs/windowsserverdocs.git
git config core.sparseCheckout true
(echo EssentialsDocs)>>.git\info\sparse-checkout
git pull origin master
=>
C : \ Users \ 사용자 이름 \ Desktop> sparse_checkout.bat
C : \ Users \ 사용자 이름 \ Desktop> pushd "C : \ Users \ 사용자 이름 \ Desktop \"
C : \ Users \ user name \ Desktop> 존재하지 않는 경우. \ ms-server-essentials-docs mkdir. \ ms-server-essentials-docs
C : \ Users \ 사용자 이름 \ Desktop> pushd. \ ms-server-essentials-docs
C : \ Users \ user name \ Desktop \ ms-server-essentials-docs> git init C : / Users / user name / Desktop / ms-server-essentials-docs / .git /에서 빈 Git 리포지토리를 초기화했습니다.
C:\Users\user name\Desktop\ms-server-essentials-docs>git remote add origin -f https://github.com/MicrosoftDocs/windowsserverdocs.git Updating origin remote: Enumerating objects: 97, done. remote: Counting objects: 100% (97/97), done. remote: Compressing objects: 100% (44/44), done. remote: Total 145517 (delta 63), reused 76 (delta 53), pack-reused 145420 Receiving objects: 100% (145517/145517), 751.33 MiB | 32.06 MiB/s, done. Resolving deltas: 100% (102110/102110), done. From https://github.com/MicrosoftDocs/windowsserverdocs * [new branch]
1106-conflict -> origin/1106-conflict * [new branch]
FromPrivateRepo -> origin/FromPrivateRepo * [new branch]
PR183 -> origin/PR183 * [new branch]
conflictfix -> origin/conflictfix * [new branch]
eross-msft-patch-1 -> origin/eross-msft-patch-1 * [new branch]
master -> origin/master * [new branch] patch-1
-> origin/patch-1 * [new branch] repo_sync_working_branch -> origin/repo_sync_working_branch * [new branch]
shortpatti-patch-1 -> origin/shortpatti-patch-1 * [new branch]
shortpatti-patch-2 -> origin/shortpatti-patch-2 * [new branch]
shortpatti-patch-3 -> origin/shortpatti-patch-3 * [new branch]
shortpatti-patch-4 -> origin/shortpatti-patch-4 * [new branch]
shortpatti-patch-5 -> origin/shortpatti-patch-5 * [new branch]
shortpatti-patch-6 -> origin/shortpatti-patch-6 * [new branch]
shortpatti-patch-7 -> origin/shortpatti-patch-7 * [new branch]
shortpatti-patch-8 -> origin/shortpatti-patch-8C:\Users\user name\Desktop\ms-server-essentials-docs>git config core.sparseCheckout true
C:\Users\user name\Desktop\ms-server-essentials-docs>(echo EssentialsDocs ) 1>>.git\info\sparse-checkout
C:\Users\user name\Desktop\ms-server-essentials-docs>git pull origin master
From https://github.com/MicrosoftDocs/windowsserverdocs
* branch master -> FETCH_HEAD
'Programing' 카테고리의 다른 글
각도 표현식 {{::}} 안의 두 콜론은 무엇을 의미합니까? (0) | 2020.09.14 |
---|---|
파일 체크 아웃없이 git 분기 전환 (0) | 2020.09.14 |
x86-64 시스템에 48 비트 가상 주소 공간 만있는 이유는 무엇입니까? (0) | 2020.09.14 |
여러 열에서 중복 항목을 찾으려면 어떻게합니까? (0) | 2020.09.14 |
Xcode-프레임을 잃지 않고 한 뷰에서 다른 뷰로 컴포넌트를 드래그하는 방법이 있습니까? (0) | 2020.09.13 |