This is what happens:
git commit --amend
and leave the same commit message as HEADgit push
And now I get
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commit each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean
I want to understand:
Follow. Occasionally, you or your team members may run into a diverged branch. A diverged branch means the data you're looking at locally isn't the same as what is currently stored on our servers.
Removed file merge conflicts To resolve a merge conflict caused by competing changes to a file, where a person deletes a file in one branch and another person edits the same file, you must choose whether to delete or keep the removed file in a new commit.
You changed an existing pushed commit, creating your own version (since its content has changed)
--x---Y (master: that is the X amended)
\
--X (origin/master)
That is why you have 1 and 1 different commit each between master and origin/master
What can I do to prevent this?
Don't "amend" an existing pushed commit (only local not-yet-pushed one)
How do I reconcile master with local after a git amend?
Simply rebase on top of origin/master, then push
git rebase origin/master
--x--X---Y' (master)
|
(origin/master)
git push
--x--X---Y' (master, origin/master)
If you are the only one working on the project after your amend you could have run
git push -f origin master
If you are not the only one working on the project be carefull of what you do because it's rewriting history.
Here is a great article about amend :
https://medium.com/@igor_marques/git-basics-adding-more-changes-to-your-last-commit-1629344cb9a8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With