Programing

재설정을 원격 저장소에 강제로 푸시하는 방법은 무엇입니까?

lottogame 2020. 9. 11. 19:27
반응형

재설정을 원격 저장소에 강제로 푸시하는 방법은 무엇입니까?


원격 마스터 브랜치가 엉망이되었습니다. 현재 개발 코드는 최신 커밋과 함께 마스터 브랜치에 있습니다. 분명히 개발 코드는 마스터 브랜치에 대해 준비되지 않았습니다.

그래서 내 로컬 저장소에서 최신 태그 인 git reset --hard (Tag). 이제 마스터 브랜치가 내 로컬 저장소에서 정확합니다. 이제 변경 사항을 원격 저장소에 푸시하려고 git push origin master하면 오류가 발생합니다.

To (REMOTE GIT REPOSITORY LOCATION)
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '(REMOTE GIT REPOSITORY LOCATION)'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

그래서 주변을 둘러 본 후 --force옵션을 찾았습니다 . 그래서 원격 저장소에 강제 푸시를 git push --force origin master했지만 여전히 오류가 발생했습니다.

Total 0 (delta 0), reused 0 (delta 0)
remote: error: denying non-fast-forward refs/heads/master (you should pull first)
To (REMOTE GIT REPOSITORY LOCATION)
 ! [remote rejected] master -> master (non-fast-forward)
error: failed to push some refs to '(REMOTE GIT REPOSITORY LOCATION)'

마스터에있을 수없는 개발 코드가 포함되어 있기 때문에 마스터에 끌어 올 수 없습니다.


이 메시지는 빨리 감기가 아닌 푸시를 할 수 없음을 의미합니다.

원격 저장소는 대부분 denyNonFastforwards = true구성에 있습니다. 그것을 변경 git push --force하면 작동합니다.

설정을 변경하려면 원격 저장소가있는 시스템에 액세스해야합니다. 거기에서 git config receive.denynonfastforwards false.


리모컨은 빨리 감기를 허용하지 않습니다.

최선의 선택은 git revert거기에 있으면 안되고 앞으로 더 조심해야 모든 커밋입니다.

git revert [commit]무엇을 [commit]했는지 취소하는 새로운 커밋을 생성합니다 .


다음 스타일에서 강제 푸시를 영구적으로 활성화하는 단계

git push -f myrepo my-branch

원격 저장소에서 ".git"로 끝나는 폴더에서 "config"라는 파일을 편집합니다.

푸시에 실패한 git의 명령 줄 출력에서 ​​다음과 같은 줄을 찾습니다.

error: failed to push some refs to 'ssh://user@some-remote-server.mycompany.com/srv/git/myrepo.git

그때

ssh user@some-remote-server.mycompany.com
cd /srv/git/myrepo.git
vi config

"denyNonFastforwards"를 false로 설정

"config"에서

[receive]
        denyNonFastforwards = false

Now you can push from your local machine with -f

git push -f myrepo my-branch

Try using the -f flag and putting it after the remote branch name.

git push origin master -f


You're not allowed to do git push that is not fast-forward.

  1. If the remote is GitHub, go to https://github.com/$USER/$REPO/settings/branches and un-protect the branch in question.

    enter image description here

    You have to be admin of the repo to do that.

  2. If the remote is your own git server, run git config receive.denynonfastforwards false there.


The best way around this is to delete the remote branch and re-send it:

git push origin master --delete
git push origin master

The problem occurs as the current branch isn't configured properly for the PULL. First check whether the upstream branch is properly configured for the pull using - git remote show origin. You can find it under the section - Local branches configured for 'git pull':. If not, configure it using:

git config branch.MYBRANCH.merge refs/heads/MYBRANCH

Give appropriate branch name for the place holder - MYBRANCH


I'm using this group of commands to reset my remote repo, this will re-initialize your local repo and relink with your remote repo then force push the updates.

I think this way won't work in your case, but may be useful for someone else

go to the source folder then run the commands : note that https://github.com/*.git is your remote repo link

git init
git remote add origin https://github.com/*.git
git add .
git commit -m "initial commit"
git push origin master -f
git push --set-upstream origin master

**Note: this will clear all your git history on your master branch**


For me, @svick 's hint pointed in the right direction. Since the git server I wanted to modify is actually my box, I logged into it and did a git config --global receive.denynonfastforwards false to change all repos to accept a forced non-ff push. Didn't work out of the box. What I found was that in the config there already was receive.denynonfastforwards=true set, and it couldn't be erased with git config --global --unset receive.denynonfastforwards. Doing the edit in the repo manually (vi config) worked, though.

참고URL : https://stackoverflow.com/questions/10544139/how-to-force-push-a-reset-to-remote-repository

반응형