简体   繁体   中英

Conflicts after git reset --hard

I've got a branch named master and I want to reset all changes made on this branch. Need to move all commits from branch named origin/d to master . So this is what I did (on branch master ):

git fetch -all
git reset --hard origin/d
git clean -f -d
git push origin master --force

I've got following message:

remote: error: denying non-fast-forward refs/heads/master (you should pull first)

But I don't want to pull, I just want move all commits from branch d to branch master (ignoring all local/non-local commits on branch master ).

When I put git pull I've got many conflicts that I do not want to resolve. Could anyone help me and tell me what is the simplest way to do that?

The error message indicates that (1) your server is disallowing forced updates (the --force argument), and (2) for some reason Git wants to push m to master .

To temporarily work around the second issue, you can do:

git push origin m:refs/heads/m --force-with-lease

(It's better to use --force-with-lease rather than --force , because the former will only overwrite if your remote-tracking branch is up-to-date. If someone else happened to push commits since you last fetch ed, then --force will overwrite those, causing work to be lost.)

However, if your server is disallowing forced updates, then it will probably reject that command as well. If you have admin access to your server, then one option is to change that. Otherwise, to work around that, you should be able to delete the branch and then push:

git push origin --delete m
git push origin m:refs/heads/m

If that doesn't work, then you'll have to contact your server administrator and ask them to allow you to delete branches and/or to force-update them.

Yeap you give this error cause you don't have latest changes from repository, so you should pull them.

git reset --hard HEAD
git pull --rebase // fetch and pull together

and after resolving conflicts (if they will exist) you will can doing push

git push origin master 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM