0

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.

  • 2
    The differences are explained in `git help reset` and [the online documentation of `git reset`](https://git-scm.com/docs/git-reset#git-reset-emgitresetemltmodegtltcommitgt). In a nutshell, `git reset ` followed by `git add .` has the same effect as `git reset --soft ` – axiac Oct 05 '18 at 22:35
  • That makes sense, if you want to add a short answer for humans that would be helpful, the git docs are not always that human friendly –  Oct 05 '18 at 22:38

1 Answers1

0

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.

gahooa
  • 131,293
  • 12
  • 98
  • 101