git - Undo changes (commited and pushed) -


i have 2 commit's have commited , pushed. need return code state 'two commits ago'.

i can use git reset --hard <hash> locally, can not push changes:

hint: updates rejected because tip of current branch behind

how can return code previous commit in central repository?

update:

ms-app-actual/mobile-application » git reset --hard e50fa38c4865bd82fce7ddcf1e05d94012266364   ‹master› head @ e50fa38 move attachment class separate project   ms-app-actual/mobile-application » git push --force                                            ‹master› total 0 (delta 0), reused 0 (delta 0) remote: gitlab: don't have permission ssh://git@aaa.bb.cc.dd:2222/ms-mobile-app/mobile-application.git  ! [remote rejected] master -> master (pre-receive hook declined) error: failed push refs 'ssh://git@aaa.bb.cc.dd:2222/ms-mobile-app/mobile-application.git' 

but can pull:

ms-app-actual/mobile-application » git pull                                                    ‹master› updating e50fa38..cebcabf fast-forward 

and make ordinary commits.

i using gitlab.

doing git reset --hard , force pushing changes remove commits. however, need careful doing this. if else has pulled changes, cause problems history. , seems gitlab preventing doing anyway.

the best way create new commit undoes changes , push that. way pulls not have issues merging in changes. there couple of ways of doing this.

1) create 2 revert commits , rebase them one

git revert <sha of commit 1> git revert <sha of commit 2> git rebase -i <sha of commit in state> //squash 2 revert commits 1 git push 

2) checkout changed files commit , commit changes

git diff --name-only head..head~3 | xargs git checkout head~3 --  //this should result in files modified in 2 commits being changed. git commit -am "reverting changes commits" git push 

both of these solutions, result in same thing. new commit inverse of changes made in 2 don't want. safest way undo changes pushed remote repository.

as rule of thumb: once push changes remote repository, should consider them permanent.

since tried reset --hard, in order commits can undo them. need git pull.


Comments

Popular posts from this blog

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -