What is the difference between
git reset --soft origin/dev
and
git reset origin/dev
Hopefully it's not a big difference because I might have just screwed something up by accident.
What is the difference between
git reset --soft origin/dev
and
git reset origin/dev
Hopefully it's not a big difference because I might have just screwed something up by accident.
In the form git reset --soft <commit>
, git will merely update what "commit" it is sitting on, without touching the index or working tree.
This is occasionally handy when the state of your index or working tree is accurate but it is based on the wrong commit (or you want to remove a commit, so you reset --soft to a previous one). For example:
to clear history:
git reset --soft <first-commit-in-log>
git commit --amend
That will have the effect of git replacing the first commit and discarding all subsequent ones, but still having the exact same files.
In the form git reset origin/dev
, git will take the contents of whatever origin/dev is (a tree or commit pointing to a tree), and update the index with it's contents. This still does not affect the working tree, but the files in the index will show up as ready to commit (the ones that were in origin/dev
).
This is useful for yanking a file out of history
git reset <commit> path/to/file
git checkout path/to/file
The first command digs the version of path/to/file
out of the history at <commit>
and puts it in the index. The second command takes the new contents of the index and overwrites whatever is in your working tree for that file.
git reset
is a super powerful command that has a lot of possibilities. Suggest you clone a repo and play with it.