반응형
Git에서 하나의 파일 만 가져올 수 있습니까?
테스트가 깨진 Git 브랜치에서 작업 중이며 이미 수정 된 다른 브랜치에서 이러한 테스트를 가져 와서 변경하지 않고 병합하고 싶습니다.
내가 할 수 있다는 걸 알아
git pull origin that_other_branch
그러나 이것은 아직 준비되지 않았기 때문에 많은 다른 파일을 병합하려고 시도합니다.
다른 지점에서 지정된 파일 만 가져오고 병합 할 수 있습니까?
이 질문에 대한 모든 대답은 분기를 변경하지 않고 로컬로 변경된 파일을 리포지토리 버전으로 되 돌리는 방법이므로 하나의 파일에 대한 Git 풀 요청 의 복제본이 아닙니다 .
이 방법으로 하나의 파일 만 가져오고 체크 아웃 할 수 있습니다.
git fetch
git checkout -m <revision> <yourfilepath>
git add <yourfilepath>
git commit
git checkout
명령 과 관련하여 : <revision>
-브랜치 이름, 즉 origin/master
<yourfilepath>
저장소 이름 ( copy path
GitHub의 파일 페이지에서 버튼을 클릭하여 얻을 수 있음)을 포함하지 않습니다.README.md
이것을 연구 할 때 방금 생각해 낸 약간 쉬운 방법이 있습니다.
git fetch {remote}
git checkout FETCH_HEAD -- {file}
git checkout master -- myplugin.js
마스터 = 지점 이름
myplugin.js = 파일 이름
@Mawardy의 대답은 나를 위해 일했지만 내 변경 사항은 원격에 있었으므로 원점을 지정해야했습니다.
git checkout origin/master -- {filename}
예, 과정은 다음과 같습니다.
# Navigate to a directory and initiate a local repository
git init
# Add remote repository to be tracked for changes:
git remote add origin https://github.com/username/repository_name.git
# Track all changes made on above remote repository
# This will show files on remote repository not available on local repository
git fetch
# Add file present in staging area for checkout
git check origin/master -m /path/to/file
# NOTE: /path/to/file is a relative path from repository_name
git add /path/to/file
# Verify track of file(s) being committed to local repository
git status
# Commit to local repository
git commit -m "commit message"
# You may perform a final check of the staging area again with git status
참고 URL : https://stackoverflow.com/questions/16230838/is-it-possible-to-pull-just-one-file-in-git
반응형
'Programming' 카테고리의 다른 글
여러 확인란에서 $ _POST 받기 (0) | 2020.06.09 |
---|---|
컨트롤에 툴팁을 어떻게 추가합니까? (0) | 2020.06.09 |
SourceTree에서 두 가지에 시각적 차이를 얻는 방법이 있습니까? (0) | 2020.06.09 |
루프 내에서 변수를 선언하는 데 오버 헤드가 있습니까? (0) | 2020.06.09 |
Java / Spring에서 Scala / Lift를 사용하는 이유는 무엇입니까? (0) | 2020.06.09 |