What's the difference between git reset --mixed, --soft, and --hard?

后端 未结 15 1477
野的像风
野的像风 2020-11-22 14:39

I\'m looking to split a commit up and not sure which reset option to use.

I was looking at the page In plain English, what does "git reset" do?, but I real

15条回答
  •  执笔经年
    2020-11-22 15:15

    Please be aware, this is a simplified explanation intended as a first step in seeking to understand this complex functionality.

    May be helpful for visual learners who want to visualise what their project state looks like after each of these commands:

    Given: - A - B - C (master)


    For those who use Terminal with colour turned on (git config --global color.ui auto):

    git reset --soft A and you will see B and C's stuff in green (staged and ready to commit)

    git reset --mixed A (or git reset A) and you will see B and C's stuff in red (unstaged and ready to be staged (green) and then committed)

    git reset --hard A and you will no longer see B and C's changes anywhere (will be as if they never existed)


    Or for those who use a GUI program like 'Tower' or 'SourceTree'

    git reset --soft A and you will see B and C's stuff in the 'staged files' area ready to commit

    git reset --mixed A (or git reset A) and you will see B and C's stuff in the 'unstaged files' area ready to be moved to staged and then committed

    git reset --hard A and you will no longer see B and C's changes anywhere (will be as if they never existed)

提交回复
热议问题