1

I make this git mistake sometimes and its incredibly annoying. I was wondering whether anyone in the community had ideas for what to do when you accidentally do a commit --amend on the head of a remote branch. Right now I end up doing a pull, diffing against my own partial change, and pushing, resulting in a duplicate commit message on the HEAD.

For clarity, I'm asking the best way to fix the following:

  1. Pull remote branch (e.g. master)
  2. Make change
  3. Commit --amend change
  4. Try to push, get rejected
  5. Curse self and/or gods
Dirk
  • 599
  • 1
  • 4
  • 18
  • Pretty sure this is a duplicate of [this](http://stackoverflow.com/questions/253055/how-do-i-push-amended-commit-to-the-remote-git-repository#432518). Bad idea unless it's a repo only you and you and a couple of friends are using. – kabanus Jan 20 '17 at 19:21
  • 1
    Possible duplicate of [How do I push amended commit to the remote Git repository?](http://stackoverflow.com/questions/253055/how-do-i-push-amended-commit-to-the-remote-git-repository) – kabanus Jan 20 '17 at 19:21

1 Answers1

0

Try:

git stash save -u
git pull -f --rebase
git stash apply

The second command will update your local brach based on the remote one while preserving the additional commits to your local branch. Tell us whether it helps.

Grzegorz Górkiewicz
  • 4,496
  • 4
  • 22
  • 38