I encountered a scenario in which I don't understand the outcome.
My team is working on a feature branch with commits:
A--B--C
A co-worker pushes two new commits:
A--B--C--D--E
Me, not realizing anyone else is pushing code to this branch, I force push an ammended commit:
A--B--C'
After I realized my error, I suggested that he try (on his repo, where D and E are still present):
git pull -r
git push
My thinking was that his two commits (D, E) were no longer in the history for the branch and so, upon pull, git would try to merge them into the history. My expectation was that D and E would be rebased on top of C', but that didn't happen. Instead (paraphrased):
$ git pull -r
+ commit...commit branch -> origin/branch (forced update)
$ git push
Everything up-to-date
and D and E were no where to be seen. I thought that perhaps he'd done some other actions on his repo and so it might have been in some unknown state, so we found the hash for E in the reflog, and did git reset --hard <E>
a few times to try again (mostly because I was curious why it hadn't gone as I'd expected) and got the same result.
I'm sure I've misunderstood something, but I'm not sure what. Why didn't the git pull -r
rebase the "new" commits D and E (ie. the ones I'd inadvertently removed from history) on top of C'?
As a few have pointed out: C should've been included in my expectation as well. I wasn't thinking about that, but I understand why, and that makes sense.
My expectation was that the "new" commits (now updated to be C, D, E; even though, had it worked, would not have been what I wanted) would have been rebased, but they were not and I don't understand why.
@matt's comment about the commits having previously been pushed was interesting. If someone could elaborate on that mechanism that seems like a potential answer.