programing

Git: 로컬 변경을 실행 취소할 수 없습니다(오류: 경로...가 병합되지 않음).

i4 2023. 5. 1. 19:57
반응형

Git: 로컬 변경을 실행 취소할 수 없습니다(오류: 경로...가 병합되지 않음).

다음과 같은 작업 트리 상태가 있습니다.

$ git status foo/bar.txt
# On branch master
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#       deleted by us:      foo/bar.txt
#
no changes added to commit (use "git add" and/or "git commit -a")

파일foo/bar.txt이 있으며 다시 "변경되지 않은 상태"로 되돌리고 싶습니다('svn revert'와 유사).

$ git checkout HEAD foo/bar.txt
error: path 'foo/bar.txt' is unmerged
$ git reset HEAD foo/bar.txt
Unstaged changes after reset:
M       foo/bar.txt

이제 혼란스러워지고 있습니다.

$ git status foo/bar.txt
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   foo/bar.txt
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   foo/bar.txt
#

섹션과 수정된 섹션 모두에서 동일한 파일이 있습니까?어떻게 해야 하나?

당신은 그것을 잘못된 방법으로 했습니다.먼저 재설정하고 파일의 스테이징을 해제한 다음 체크아웃하여 로컬 변경사항을 되돌려야 합니다.

사용해 보십시오.

$ git reset foo/bar.txt
$ git checkout foo/bar.txt

이것은 저에게 완벽하게 효과가 있었습니다.

$ git reset -- foo/bar.txt
$ git checkout foo/bar.txt
git checkout origin/[branch] .
git status

끝에 점(.)을 기록합니다.그리고 모든 것이 잘 될 것입니다.

최근 Git 버전에서는git restore과부하보다 원하지 않는 로컬 변경을 되돌리는 "더 나은" 방법이어야 합니다.checkout좋습니다. 합리적인 가격입니다. 일반적인 작업을 위해 특별히 제작된 멋진 도구입니다.

하지만, 여기 제가 새로 만든 "가장 좋아하는" 기트 버그가 있습니다.예, 저는 어떤 멍청이가 "그것은 버그가 아니라 의도적으로 하는 것입니다."라고 말할 것이라는 것을 알고 있습니다.하지만 이런 종류의 사용자 인터페이스를 통해 저는 "버그"라는 별명을 지지합니다.

% git restore LEGAL
error: path 'LEGAL' is unmerged
# okay, fine...
% git restore --ignore-unmerged LEGAL
warning: path 'LEGAL' is unmerged
# Arg, what?!

(2.25.1 git로 표시)

첫째, 도구가 특정한 조건 때문에 무언가를 하기를 거부할 때, 그것은 단순한 경고가 아닙니다.적어도 작업이 수행되지 않았다고 표시되어야 합니다.이제 수술이 실제로 수행되었는지 여부를 조사하러 가야 합니다(힌트: 그렇지 않았습니다).

물론 두 번째 문제는 분명합니다.이제 맨 페이지 항목을 보고 이 환상적인 도구가 제가 지시하는 것을 수행하지 못하는 이유를 알아보겠습니다.

   --ignore-unmerged
       When restoring files on the working tree from the index, do not
       abort the operation if there are unmerged entries and neither
       --ours, --theirs, --merge or --conflict is specified. Unmerged
       paths on the working tree are left alone.

저런!나는 여기서 사용자 인터페이스 문제에 대한 기트시 수정은 옵션의 이름을 바꾸는 것이라고 생각합니다.--ignore-unmerged로.--ignore-unmerged-except-in-cases-where-we-do-not-want-to-allow-that--consult-documentation-then-source-code-then-team-of-gurus-when-you-cannot-figure-it-out---and-wait-while-half-of-them-argue-about-why-it-is-right-as-is-while-the-other-half-advocate-adding-four-more-options-as-the-fix.

그런 다음 지역사회에 가서 해결책을 찾아보세요.어디 한번 해봐.

분명히, 저는 작업 파일에서 무대 장치로 커밋하는 것으로 나무 같은 얼룩을 해결할 수 있는 상태에서 제 심판을 받지 못했습니다.오류 색인?

위의 답변이 효과가 없으면 시도해 보십시오.

git reset -–merge

병합되지 않은 경로 오류를 수정하는 "현대적인" 방법은 다음을 사용하여 저장소를 열 때 발생할 수 있습니다.restore명령(git v2.23 이후, 2019년 8월):

# unstage the file
git restore --staged myfile

# restore the file (lose your working dir changes)
git restore myfile
git checkout foo/bar.txt

당신은 그것을 시도했습니까?(HEAD 키워드 없음)

저는 보통 이런 식으로 변경 사항을 되돌립니다.

저는 Gitstash가 모든 '더러운' 상태를 일시적으로 처리하는 데 매우 유용하다고 생각합니다.

언급URL : https://stackoverflow.com/questions/3021161/git-cant-undo-local-changes-error-path-is-unmerged

반응형