How do I make an old commit the current master commit with git?

Here are my commits:

A B C

  • git (any SCM) and compiling object files, switching branches, physiology thereof
  • Git diff of branches or commits showing file list overview in visual difftool and then selectable single file diff
  • Aborted old git rebase and lost commits since the rebase started
  • How to get rid of ESC[ characters when using git diff on Mac OS X Mavericks?
  • How do you squelch git's automatic merge message?
  • How do I import a third party lib into git?
  • With C being the current commit. I want things to look like this on origin:

    A B C A

    So A is my current commit, but B and C are retained. I currently have the repo cloned with C being the current commit. What do I need to do next to get origin how I want it?

  • The meaning of tracking in git
  • Where is Heroku getting its RSA key from? It seems to be somewhere other than ~/.ssh/
  • Jenkins - Git plugin is not creating local subdirectory for repo when started by CI
  • What are the differences between local branch, local tracking branch, remote branch and remote tracking branch?
  • How to setup Git on local network?
  • Is it Possible to Create a git Repository from an SVN Log File?
  • 2 Solutions collect form web for “How do I make an old commit the current master commit with git?”

    Commits ‘B’ and ‘C’ are progressive states of the branch’s history. To reset to ‘A’ without losing ‘B’ or ‘C’ locally, just use a new branch on origin:

    git checkout -B new-branch master
    git reset --hard <A_commit_hash>
    git push origin new-branch
    

    ‘B’ and ‘C’ will be retained on ‘master’, so you can git cherry-pick <commit_of_B_or_C> or git merge master without trouble.

    If you really want ‘B’ and C’, but want to reset ‘master’ to ‘A’, and have thought through the consequences of forcibly overwriting your remote:

    git branch archived-master master ;# create 'archived-master' branch
    git reset --hard A ;# reset master to 'A' state
    git push -f origin master ;# overwrite remote's master
    

    That’ll save ‘B’ and ‘C’ locally on the ‘archived-master’ branch.

    I would avoid git revert for this. Revert commits make commands like git bisect and git rebase more difficult, and if you ever want to reuse ‘B’ and ‘C’ it’s harder for a human to parse the history.

    git revert B C

    (this will add two commits, but the state of your tree will be as it was at A)

    Git Baby is a git and github fan, let's start git clone.