1

I amended a pushed commit. Now can't push to git repo.

I do not want to push with -f key because it will make a lot of problems to other people.

Currently I see only one solution:

  1. git clone
  2. write changed files over from a backup copy
  3. make a new commit
  4. push it

Do you know a better way?

Paul
  • 25,812
  • 38
  • 124
  • 247
  • 1
    Reset to the previous commit before the push, pull from upstream. That should put you back to before you amended. – tripleee Jun 04 '14 at 15:25
  • @tripleee: What is "upstream" in this case? – Paul Jun 05 '14 at 05:42
  • The place you already pushed to. Basically, pull back down what you already pushed, then redo as a separate commit instead of an amend. – tripleee Jun 05 '14 at 06:53

1 Answers1

0

Amending a commit generates a new commit. If you have already pushed the (previous version of the) commit to a remote repository, you cannot push the new commit without -f because that would alter the existing history of the remote. A key promise that git makes is that a given commit -- and the history leading up to that commit -- cannot be modified without generating a new commit id.

Your options are:

  • Just use git push -f and let people know, or
  • Create a new commit after the existing one and push that.

Some workflows (for example, those involving Gerrit or GitHub pull requests) rely on forced pushes as a regular operation (e.g., for updating an existing pull request). Adopting a workflow like this can give you more opportunities for fixing things "after the fact".

larsks
  • 277,717
  • 41
  • 399
  • 399