Consider the 2nd scenario in git pull --rebase lost commits after coworker's git push --force :
- Dan and Brian start with a common commit.
- Each makes a separate commit, so that the branch diverges.
- Dan pushes first.
- Brian force pushes without merging Dan's commit.
- Dan pulls with
--rebase
, and observes his history lost.
In an online test, I was asked the following question.
How can Dan compare the changes before and after the
git pull --rebase
?
I was required to respond with one single complete git command.
If I were actually working on my local repo, I would use git reflog
to retrieve the appropriate commit IDs for git diff
, but in the online test, I wasn't given such details.
Question source: online test on Codingame
A 3rd-party user rebased accidentally and incorrectly, and then force pushed it. You pulled these changes into your local repo and lost all commit history.
What command can you execute to list all changes of the repo so that you can come back to a former state corresponding to a given reference?