'git pull' 커맨드로 로컬 디렉토리에 존재하는 파일을 덮어 쓸 수 있나요??

LONGNEW·2021년 1월 6일
0

StackOverFlaw

목록 보기
12/16

와.. 무슨 한글로 썼는데 다 영어네...
https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files

Q . How do I force “git pull” to overwrite local files?
Q. 'git pull' 커맨드로 로컬 디렉토리에 존재하는 파일을 덮어 쓸 수 있나요??
How do I force an overwrite of local files on a git pull?
로컬 파일 에 존재하는 것을 git pull로 어떻게 덮어 쓸 수 있나요??
The scenario is the following:

  • 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
    소스코드를 수정하며 이미지를 추가했고, 깃허브에 다른 변경사항과 함께 push 했습니다.
  • They cannot pull updates from GitHub because Git doesn't want to overwrite their files.
    깃이 그 파일들을 덮어 씌어 주지 않아서 업데이트 한것들을 pull 하지 못합니다.
    This is the error I'm getting:

error: Untracked working tree file 'public/images/icon.gif' would be overwritten by merge

How do I force Git to overwrite them?
깃이 파일을 덮어 쓰도록 어떻게 하나요?
The person is a designer - usually,
대부분의 문제는 디자이너에게 발생했습니다.
I resolve all the conflicts by hand, so the server has the most recent version that they just need to update on their computer.
그리고 제가 모든 에러들을 해결한 후 서버에 최신 버전을 업데이트 해서 다른 팀원들은 자신의 로컬 파일만 업데이트 하면 됩니다.


⚠ Important: If you have any local changes, they will be lost.

중요 : 로컬 디렉토리에서 변경사항이 생긴다면, 모두 사라집니다.

With or without --hard option, any local commits that haven't been pushed will be lost.[*]

--hard 옵션 없을 경우엔 push된 로컬 커밋들은 삭제 됩니다.

If you have any files that are not tracked by Git (e.g. uploaded user content), these files will not be affected.
깃이 트래킹 하지 않는 파일이 있다면, 이것 들은 영향을 받지 않습니다.
First, run a fetch to update all origin/ refs to latest:
첫째, origin/를 업데이트 하기 위해 fetch 합니다.

git fetch --all

Backup your current branch:
자신의 현재 브랜치를 백업 합니다.

git checkout -b backup-master

Then, you have two options:
그 다음엔 두 가지 옵션이 존재합니다.

git reset --hard origin/master

OR If you are on some other branch:
마스터 브랜치에 있는 경우가 아니면.

git reset --hard origin/<branch_name>

Explanation / 설명.

git fetch downloads the latest from remote without trying to merge or rebase anything.
git fetch는 리모트 디렉토리에서 가장 최근 버전을 merge나 rebase 하지 않고 다운로드 합니다.

Then the git reset resets the master branch to what you just fetched.
git reset은 금방 fetch 한 버전과 같게(?) 마스터 브랜치를 리셋합니다.

The --hard option changes all the files in your working tree to match the files in origin/master
--hard 옵션은 본인의 working tree 에 존재하는 파일들을 origin/master와 동일하게 변경 시킵니다.

Maintain current local commits / 현재의 로컬 커밋을 유지.

[*]: It's worth noting that it is possible to maintain current local commits by creating a branch from master before resetting:
master 브랜치를 리셋하기 전에 브랜치를 생성해서 현재의 로컬 커밋들을 유지 할 수 있습니다.

git checkout master
git branch new-branch-to-save-current-commits
git fetch --all
git reset --hard origin/master

After this, all of the old commits will be kept in new-branch-to-save-current-commits.
실행한 후엔, 모든 커밋들은 new-branch-to-save-current-commits 브랜치에 존재합니다.

Uncommitted changes / 커밋 하지 않은 것들.

Uncommitted changes, however (even staged), will be lost.
커밋 되지 않은 것들, 심지어 스테이징 된 것이여도 사라집니다.
Make sure to stash and commit anything you need.
꼭 stash 하고 커밋 하길 바랍니다.
For that you can run the following:

git stash

And then to reapply these uncommitted changes:

git stash pop

0개의 댓글