Programing

"병합하기 전에 변경 사항을 커밋하거나 숨길 수 있습니다"라고 말하는 git을 어떻게 해결합니까?

lottogame 2020. 10. 2. 21:22
반응형

"병합하기 전에 변경 사항을 커밋하거나 숨길 수 있습니다"라고 말하는 git을 어떻게 해결합니까?


내 로컬 컴퓨터에서 몇 가지 업데이트를 수행하고 원격 저장소로 푸시 한 다음 변경 사항을 서버로 가져 오려고하는데 메시지가 표시됩니다.

오류 : 다음 파일에 대한 로컬 변경 사항은 병합으로 덮어 씁니다.

wp-content / w3tc-config / master.php

병합하기 전에 변경 사항을 커밋하거나 숨기십시오.

그래서 나는 달렸다.

git checkout -- wp-content/w3tc-config/master.php

다시 시도했는데 같은 메시지가 나타납니다. 나는 그것이 w3tc서버의 구성 파일에서 무언가 변경 했다고 가정하고 있습니다. 로컬 복사본이 서버에 있든 원격 복사본이 서버에 있든 상관하지 않습니다 (원격 복사본이 가장 좋다고 생각합니다). 나머지 변경 사항 (플러그인 업데이트)을 병합 할 수 있기를 원합니다.

어떤 아이디어?


로컬 수정과 병합 할 수 없습니다. Git은 잠재적으로 중요한 변경 사항을 잃지 않도록 보호합니다.

세 가지 옵션이 있습니다.

  • 다음을 사용하여 변경 사항 커밋

    git commit -m "My message"
    
  • 숨겨라.

    스 태싱은 변경 사항을 푸시 할 수있는 스택 역할을하며 역순으로 팝합니다.

    숨기려면 다음을 입력하십시오.

    git stash
    

    병합을 수행 한 다음 숨김을 가져옵니다.

    git stash pop
    
  • 로컬 변경 사항 무시

    git reset --hard
    또는 사용git checkout -t -f remote/branch

    또는 : 특정 파일에 대한 로컬 변경 사항 취소

    사용 git checkout filename


git stash
git pull <remote name> <remote branch name> (or) switch branch
git stash apply --index

첫 번째 명령은 변경 사항을 숨김에 임시로 저장 하고 작업 디렉토리에서 제거합니다.

두 번째 명령은 분기를 전환합니다.

세 번째 명령은 숨김에 저장 한 변경 사항을 복원합니다 (이 --index옵션은 준비된 파일이 여전히 준비되었는지 확인하는 데 유용합니다).


다음 방법 중 하나를 시도 할 수 있습니다.

리베이스

간단한 변경의 경우 변경 사항을 가져 오는 동안 그 위에 리베이스를 시도하십시오.

git pull origin master -r

따라서 가져 오기 후 업스트림 브랜치 위에 현재 브랜치를 적용합니다.

이는 checkout master, fetchrebase origin/mastergit 명령 동일 합니다.

이것은 잠재적으로 위험한 작동 모드입니다. 그것은 당신이 이미 그 역사를 출판했을 때 좋은 징조가 아닌 역사를 다시 씁니다. git-rebase(1)주의 깊게 읽지 않았다면이 옵션을 사용하지 마십시오 .


점검

로컬 변경 사항에 신경 쓰지 않는 경우 다른 분기 (강제 사용)로 전환하고 다시 전환 할 수 있습니다.

git checkout origin/master -f
git checkout master -f

초기화

로컬 변경에 신경 쓰지 않는다면 HEAD (원래 상태)로 재설정하십시오. 예 :

git reset HEAD --hard

If above won't help, it may be rules in your git normalization file (.gitattributes) so it's better to commit what it says. Or your file system doesn't support permissions, so you've to disable filemode in your git config.

Related: How do I force "git pull" to overwrite local files?


So the situation that I ran into was the following:

error: Your local changes to the following files would be overwritten by merge: wp-content/w3tc-config/master.php Please, commit your changes or stash them before you can merge.

except, right before that, was remote: so actually this:

remote: error: Your local changes to the following files would be overwritten by merge: some/file.ext Please, commit your changes or stash them before you can merge.

What was happening was (I think, not 100% positive) the git post receive hook was starting to run and screwing up due to movement changes in the remote server repository, which in theory, shouldn't have been touched.

So what I ended up doing by tracing through the post-receive hook and finding this, was having to go to the remote repository on the server, and there was the change (which wasn't on my local repository, which, in fact, said that it matched, no changes, nothing to commit, up to date, etc.) So while on the local, there were no changes, on the server, I then did a git checkout -- some/file.ext and then the local and remote repositories actually matched and I could continue to work, and deploy. Not entirely sure how this situation occurred, though a couple dozen developers plus IT changes may had something to do with it.


Try this

git stash save ""

and try pull again


WARNING: This will delete untracked files, so it's not a great answer to this question.

In my case, I didn't want to keep the files, so this worked for me:

Git 2.11 and newer:

git clean  -d  -fx .

Older Git:

git clean  -d  -fx ""

Reference: http://www.kernel.org/pub/software/scm/git/docs/git-clean.html

  • -x means ignored files are also removed as well as files unknown to git.

  • -d means remove untracked directories in addition to untracked files.

  • -f is required to force it to run.


Asking for commit before pull

  • git stash
  • git pull origin << branchname >>

If needed :

  • git stash apply

In my case, I backed up and then deleted the file that Git was complaining about, committed, then I was able to finally check out another branch.

I then replaced the file, copied back in the contents and continued as though nothing happened.


This is probably being caused by CRLF issues.

See: Why should I use core.autocrlf=true in Git?

Use this to pull and force update:

git pull origin master
git checkout origin/master -f

I tried the first answer: git stash with the highest score but the error message still popped up, and then I found this article to commit the changes instead of stash 'Reluctant Commit'

and the error message disappeared finally:

1: git add .

2: git commit -m "this is an additional commit"

3: git checkout the-other-file-name

then it worked. hope this answer helps.:)


For me, only git reset --hard worked.

Commiting was not an option, as there was nothing to commit.

Stashing wasn't an option because there was nothing to stash.

Looks like it could have been from excluded files in .git/info/exclude and having git update-index --assume-unchanged <file>'ed some files.


For me, this method works best, instead of stashing. I want to bring in latest changes and keep a copy of my local changes and apply them afterwards.

  1. Stage your local changes. (do not commit) (staging required to patch new untracked files as well)

git add .

  1. Create a patch to keep record

git diff --cached > mypatch.patch

  1. Discard local changes and delete new local files

git reset --hard

  1. Pull changes

git pull

  1. Apply your patch

git apply mypatch.patch

Git will merge changes and create .rej files for changes which are not merged.

And enjoy your continued work on your feature, and commit your local changes when done.


If you are using Git Extensions you should be able to find your local changes in the Working directory as shown below:

enter image description here

If you don't see any changes, it's probably because you are on a wrong sub-module. So check all the items with a submarine icon as shown below:

enter image description here

When you found some uncommitted change:

Select the line with Working directory, navigate to Diff tab, Right click on rows with a pencil (or + or -) icon, choose Reset to first commit or commit or stash or whatever you want to do with it.

참고URL : https://stackoverflow.com/questions/15745045/how-do-i-resolve-git-saying-commit-your-changes-or-stash-them-before-you-can-me

반응형