Search code examples
gitversion-controlrebase

compare changes after merging a forced push


Consider the 2nd scenario in git pull --rebase lost commits after coworker's git push --force :

  1. Dan and Brian start with a common commit.
  2. Each makes a separate commit, so that the branch diverges.
  3. Dan pushes first.
  4. Brian force pushes without merging Dan's commit.
  5. 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?

question source


Solution

  • I tried inputting git reflog today, and the online test system accepted it.

    git reflog is the command that retrieves the past git references that a user stayed, so that's the best response for the question.

    enter image description here