0

I am relatively new to git. I was on a branch called temp, which I had created newly. I did 3 commits and pushed. Then I did a reset back to the 2nd commit and made some changes.

git pull gives me:

You asked me to pull without telling me which branch you want to merge with, and 'branch.temp.merge' in your configuration file does not tell me, either. Please specify which branch you want to use on the command line and try again (e.g. 'git pull '

git push gives me:

! [rejected] temp -> temp (non-fast-forward) error: failed to push some refs to 'https://myserver.com/git/project' 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.

I actually want to delete the 3rd commit which I had already pushed, and push the latest commit I have done after resetting to the 2nd commit. How do I do that?

schumacher574
  • 1,081
  • 1
  • 14
  • 32

1 Answers1

0

I would like to preface this with be very careful using the force option -f. It is a bad thing to change the history of a remote repository. See this answer for ways to workaround doing a forced push.

That being said, if you are the only one pulling from the remote repository and if you absolutely do not care about the 3rd commit which was already pushed, you can do a forced push. I'm assuming when you checked out your 2nd commit, you updated your local branch to that commit. Be aware, you will forever lose the 3rd commit in your remote repository.

git push -f <repo> <branch> (example: git push -f origin master)

That is, of course, if your local branch name matches the remote branch name. If not, you would do:

git push -f <repo> <local branch>:<remote branch>

Community
  • 1
  • 1
schumacher574
  • 1,081
  • 1
  • 14
  • 32