질문
GIT 당기는 로컬 파일의 덮어 쓰기를 어떻게 강요합니까?
시나리오는 다음과 같습니다.
- A team member is modifying the templates for a website we are working on
- They are adding some images to the images directory (but forgets to add them under source control)
- They are sending the images by mail, later, to me
- I'm adding the images under the source control and pushing them to GitHub together with other changes
- They cannot pull updates from GitHub because Git doesn't want to overwrite their files.
이것은 내가 얻는 오류입니다.
error: Untracked working tree file 'public/images/icon.gif' would be overwritten by merge
Git을 어떻게 덮어 쓸 수 있습니까?그 사람은 디자이너입니다. 일반적으로 모든 충돌을 손으로 해결하므로 서버에는 컴퓨터에서 업데이트해야 할 가장 최근의 버전이 있습니다.
답변
❏ 중요 : 로컬 변경 사항이 있으면 잃어 버릴 것입니다 (추적 된 경우).또한 - 하드 옵션이 있거나 없거나 푸시되지 않은 지역 커밋이 손실됩니다. [*]
git (예 : 업로드 된 사용자 콘텐츠)에서 추적되지 않은 파일이있는 경우이 파일은 영향을받지 않습니다.
먼저 모든 원본 /
git fetch --all
현재 지점 백업 :
git branch backup-master
그런 다음 두 가지 옵션이 있습니다.
git reset --hard origin/master
또는 다른 지점에있는 경우 :
git reset --hard origin/<branch_name>
설명:
Git Fetch는 모든 것을 병합하거나 리베이스하지 않고도 최신 버튼을 다운로드합니다.
그런 다음 git 재설정은 마스터 브랜치를 방금 가져온 것으로 재설정합니다.--hard 옵션은 작업 트리의 모든 파일을 원본 / 마스터의 파일과 일치하도록 변경합니다.
현재의 지역 커밋을 유지합니다
[*] : 재설정하기 전에 마스터에서 지점을 만들어 현재 로컬 커밋을 유지할 수 있다는 점을 주목할 가치가 있습니다.
git checkout master
git branch new-branch-to-save-current-commits
git fetch --all
git reset --hard origin/master
그 후에 모든 노인들은 새로운 지점 - 저장 - 현재의 커밋에 보관 될 것입니다.
커밋되지 않은 변경 사항
그러나 커밋되지 않은 변경 사항은 (심지어 단계적으로) 잃어버린 것입니다.당신이 필요로하는 것을 숨기고 커밋해야합니다.이를 위해 다음을 실행할 수 있습니다.
git stash
그리고 이러한 커밋되지 않은 변경 사항을 다시 적용하십시오.
git stash pop
출처:
https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files
최근댓글