git reset . For example, in the second most relevant article on the request “git reset”, the author writes that “this action can be of two types: soft (soft reset) and hard (hard reset).” The --mixed mode, used by default, for some reason did not receive a mention.git reset , after reading the topic of ambiguity should not remain.git add . When you do git commit , only what was in the index will be committed to the repository.- A - B - C (master) git reset --soft B HEAD will point to B and changes from commit C will be in the index, as if you had added them with the git add command. If you execute git commit you will get a commit completely identical to C--mixed mode --mixed used by default, i.e. git reset --mixed = git reset- A - B - C (master) git reset --mixed B or git reset B HEAD will again point to B , but this time the changes from C will not be in the index and if you run git commit here, nothing will happen. There is nothing in the index. We have all the changes from C , but if you run git status then you will see that all changes are not staged. To commit them, you must first add them to the index with the git add command and only after that git commit .- A - B - C (master)--hard as well as --mixed move HEAD to B and clear the index, but unlike --mixed hard reset will change the files in your working directory . If you run git reset --hard B then the changes from C , as well as the non-committed changes, will be deleted and the files in the repository will be the same as B. Considering that this mode implies loss of changes, you should always check git status before you perform a hard reset to make sure that there are no uncommitted changes (or they are not needed).git reset modes:| changes the index | changes files in the working directory | must be attentive | |
|---|---|---|---|
reset --soft | not | not | not |
reset [--mixed] | Yes | not | not |
reset --hard | Yes | Yes | Yes |
Source: https://habr.com/ru/post/203282/
All Articles