Throw away local commits in Git

前端 未结 20 1694
遥遥无期
遥遥无期 2020-12-02 03:08

Due to some bad cherry-picking, my local Git repository is currently five commits ahead of the origin, and not in a good state. I want to get rid of all these commits and st

20条回答
  •  伪装坚强ぢ
    2020-12-02 03:46

    Find the sha1 for the commit you want to revert to:

    za$ git reflog
    ... snip ...
    cf42fa2... HEAD@{0}: commit: fixed misc bugs
    ~
    ~
    cf42fa2... HEAD@{84}: commit: fixed params for .....
    73b9363... HEAD@{85}: commit: Don't symlink to themes on deployment.
    547cc1b... HEAD@{86}: commit: Deploy to effectif.com web server.
    1dc3298... HEAD@{87}: commit: Updated the theme.
    18c3f51... HEAD@{88}: commit: Verify with Google webmaster tools.
    26fbb9c... HEAD@{89}: checkout: moving to effectif
    

    And then use --mixed flag so that you "reset HEAD and index":

    za$ git reset --mixed cf42fa2
    

    Available flags:

    za$ git reset -h
    
    -q, --quiet           be quiet, only report errors
    --mixed               reset HEAD and index
    --soft                reset only HEAD
    --hard                reset HEAD, index and working tree
    --merge               reset HEAD, index and working tree
    --keep                reset HEAD but keep local changes
    --recurse-submodules[=]
                          control recursive updating of submodules
    -p, --patch           select hunks interactively
    -N, --intent-to-add
    

提交回复
热议问题