Reputation:
I've always known that if I've already pushed a commit I should never change its hash (rebase it, --amend it) and then push it up again cause you'll end up with (probably) two identical commits but with different hashs.
If I pull from that remote how can I possibly know that something like that happened? What's the matter with having two identical commits with different hashs?
Upvotes: 0
Views: 43
Reputation: 151654
You're asking "what happens if I pull". Nothing, because you'll be in sync, given you've force pushed the rewritten history. The problem will be when multiple people use the same remote repository.
Say, you amend, rebase or otherwise rewrite the latest commit. In essence, this deletes the most recent commit and writes a new one on top of the previous one. Now you push this to the remote repository, and it'll be rejected, because your newest commit has no relation to the latest commit the remote knows about.
So you'll have to force push, overwriting the remote branch.
Now if another developer pulls from that remote, they'll end up in trouble: they still have that older commit that you removed, and their local repo can't match your repo to any tree in their repo.
See Git pull after forced update how to resolve that.
So if you really want to rewrite already pushed history, you need to carefully coordinate that with other users of that remote repository.
So to answer your question, how you'll discover a force pushed commit: you won't be able to pull.
Upvotes: 0
Reputation: 9114
To re-push a changed commit- you must specify the -f
option. This means changing history (you are saying 'this commit that I already pushed - I want it removed in the past').
This breaks things for anyone who has pulled in the meantime. Their next pull or push will result in conflicts and a need for a merge - so git will tell them.
In other words, git push -f
is allowed:
Upvotes: 1
Reputation: 6088
If I pull from that remote how can I possibly know that something like that happened? As you've already noted, the hashes will differ if you've already pulled said commit. You may not realize it's the same commit if the commit message changed too.
What's the matter with having two identical commits with different hashs? You will most likely cause conflicts for yourself and anyone else working on the repo.
See https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History for more info.
Upvotes: 0