Rayden C
Rayden C

Reputation: 149

reset an origin to a certain commit

I, for mistake pushed a branch 'dev' to my 'origin/dev' in the repository, so now i would like to reset those branches to this commit 226b5cf7.

i already tried this: git reset --hard 226b5cf7 (so now my dev is reset to that commit) git push --force origin 226b5cf7:dev (to reset origin/dev, BUT NOT WORKING!!!)

i get this message: remote: error: denying non-fast-forward refs/heads/dev (you should pull first) To ssh://demadev/volume1/Git/smile.git ! [remote rejected] 226b5cf7 -> dev (non-fast-forward) error: failed to push some refs to 'ssh://codinera@demadev/volume1/Git/smile.git'

Upvotes: 1

Views: 122

Answers (2)

Serge
Serge

Reputation: 12354

Since you cannot do it due to the permissions on the remote node, there is another way: restore the old state of the the commit and push it as a new commit.

This command will checkout all files in from your commit into the current dirctory.

git checkout  226b5cf7 -- .

It will not remove newly created files though. You need to find them by diffing file lists against the reset then and remove manually.

git diff 226b5cf7  --name-status

Now you can commit and push.

Then you can restore your state before update in a similar manner to be able to push it later.

Upvotes: 0

torek
torek

Reputation: 488193

i already tried this: git reset --hard 226b5cf7 (so now my dev is reset to that commit)

This is fine, but not technically necessary. Note that you would first have to git checkout dev to make this affect your name dev.

[followed by] git push --force origin 226b5cf7:dev (to reset origin/dev, BUT NOT WORKING!!!)

This is the part that is required.

You say it is "not working". If you are also saying that the result of this command, including the --force option, is:

remote: error: denying non-fast-forward refs/heads/dev (you should pull first)
To ssh://demadev/volume1/Git/smile.git
  ! [remote rejected] 226b5cf7 -> dev (non-fast-forward)
error: failed to push some refs to 'ssh://codinera@demadev/volume1/Git/smile.git'

then this means that they—the Git at codinera@demadev/volume1/Git/smile.git—are ignoring your force option and still refusing to make the change you requested. (This would be the normal response to an attempt without the --force flag.)

If this is the case, there is no way for you to make this change directly. You will have to find someone who does have permission to make the change, make the change. This may involve logging in on the machine named demadev. The Git repository there may have receive.denyNonFastForwards set to true.

Upvotes: 1

Related Questions