How to force push a reset to remote repository?

后端 未结 10 1825
生来不讨喜
生来不讨喜 2020-11-29 18:49

Our remote master branch somehow got messed up. Current development code is on the master branch along with the latest commits. Obviously, the development code is not ready

相关标签:
10条回答
  • 2020-11-29 18:56

    The remote doesn't allow non-fast-forwards.

    Your best option is to git revert all of the commits that shouldn't be there and be more careful in future.

    git revert [commit] will create a new commit that undoes whatever [commit] did.

    0 讨论(0)
  • 2020-11-29 19:04

    Steps to permanently enable force push in the following style

    git push -f myrepo my-branch
    

    Edit the file named "config" in the folder ending in ".git" on your remote repository

    In git's command-line output from the failed push, look for the line that says something like:

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

    then

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

    Set "denyNonFastforwards" to false

    In "config", set

    [receive]
            denyNonFastforwards = false
    

    Now you can push from your local machine with -f

    git push -f myrepo my-branch
    
    0 讨论(0)
  • 2020-11-29 19:06

    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.

    0 讨论(0)
  • 2020-11-29 19:08

    I solved by removing the master branch from protected and also default which is just over proted branch rules in setting of a repository.

    0 讨论(0)
  • 2020-11-29 19:09

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

    git push origin master --delete
    git push origin master
    
    0 讨论(0)
  • 2020-11-29 19:09

    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

    0 讨论(0)
提交回复
热议问题