error: git | The following untracked working tree files would be overwritten by merge, but I don't care

Lumpen·2022년 10월 10일
0

Error

목록 보기
12/41

git pull 시 추적되지 않은 작업 트리 파일들이
병합에 의해 덮어 씌어짐을 경고하는 것

git reset --hard origin/브랜치 이름

위의 방식은 추적되지 않은 모든 작업 파일을 강제로 삭제하고
origin 브랜치의 commit으로 덮어씌운다

위와 같이 할 경우 커밋되지 않은 모든 작업에 대해 손실을
일으키기 때문에 사용 전 다시 한 번 사용을 고려해야한다


When you want to merge:

git checkout -f donor-branch   # replace bothersome files with tracked versions
git checkout receiving-branch  # tracked bothersome files disappear
git merge donor-branch         # merge works

When you want to pull:

git fetch
git checkout -f origin/mybranch   # replace bothersome files with tracked versions
git checkout mybranch             # tracked bothersome files disappear
git pull origin/mybranch          # pull works

That's all you need to know to use this. Below is an explanation.

Detailed explanation
The Bothersome Files that we are going to remove:

exist in the donor branch (for git pull: the upstream branch),
do not exist in the receiving branch,
and are blocking the merge because they are present and untracked in your working directory.
git merge -f and git pull -f do not exist, but git checkout -f does.

We will use git checkout -f + git checkout to track + remove the Bothersome Files, and then your merge can proceed normally.

Step 1. This step forcibly replaces untracked Bothersome Files with tracked versions of the donor branch (it also checks out the donor branch, and updates the rest of the working dir).

git checkout -f donor-branch
Step 2. This step removes the Bothersome Files because they they are tracked in our current (donor) branch, and absent in the receiving-branch we switch to.

git checkout receiving-branch
Step 3. Now that the Bothersome Files are absent, merging in the donor branch will not overwrite any untracked files, so we get no errors.

git merge donor-branch


귀찮은 파일만 안전하게 제거/덮어쓰기
원하는 경우 merge:

git checkout -f donor-branch   # replace bothersome files with tracked versions
git checkout receiving-branch  # tracked bothersome files disappear
git merge donor-branch         # merge works

원하는 경우 pull:

git fetch
git checkout -f origin/mybranch   # replace bothersome files with tracked versions
git checkout mybranch             # tracked bothersome files disappear
git pull origin/mybranch          # pull works

이것이 이것을 사용하기 위해 알아야 할 전부입니다. 아래는 설명입니다.

상해
제거할 성가신 파일:

도너 브랜치에 존재(for git pull: 업스트림 브랜치),
수신 분기에 존재하지 않으며,
작업 디렉토리에 존재하고 추적되지 않기 때문에 병합을 차단하고 있습니다.
git merge -f존재 하지 git pull -f않지만 존재합니다 git checkout -f.

git checkout -f+ 를 사용 git checkout하여 귀찮은 파일을 추적 + 제거하면 병합이 정상적으로 진행될 수 있습니다.

1단계. 이 단계는 추적되지 않은 귀찮은 파일을 기부자 분기의 추적된 버전으로 강제로 대체합니다(또한 기부자 분기를 체크아웃하고 작업 디렉토리의 나머지 부분을 업데이트함).

git checkout -f donor-branch
2단계. 이 단계에서는 성가신 파일이 현재 (기부자) 분기에서 추적되고 우리가 전환할 대상에는 없기 때문에 제거합니다 receiving-branch.

git checkout receiving-branch
3단계 . 이제 귀찮은 파일이 없으므로 기증자 분기에서 병합해도 추적되지 않은 파일을 덮어쓰지 않으므로 오류가 발생하지 않습니다.

git merge donor-branch

profile
떠돌이 생활을 하는. 실업자는 아니지만, 부랑 생활을 하는

0개의 댓글