1

I'm trying to wrap my head around the different Git methods (Revert, Switch/Chekout, Reset)

Why would I want to do a Mixed or Soft reset? I'm a VC newbie so maybe I'm missing something. I thought the point of the above was to change my local files to some other version (from Git repo)

FractalSpace
  • 5,577
  • 3
  • 42
  • 47
Clay Nichols
  • 11,848
  • 30
  • 109
  • 170
  • 1
    Already answered (for the "soft" part) in http://stackoverflow.com/q/5203535/6309 – VonC Nov 21 '16 at 22:52
  • 1
    You mean a mixed or soft `reset`, don't you? – rodrigo Nov 21 '16 at 22:53
  • There's no such thing as a "soft revert". This terminology is specific to Git (Mercurial uses the word "revert" differently, for instance), but in Git, *revert* means, more or less, "make a *new* commit that undoes something from a *previous* commit". You are looking at *reset*, which is a significantly more complicated command (I sometimes argue that it should be at least two or three separate commands, instead of one big "reset"). – torek Nov 21 '16 at 23:19
  • The point of a soft reset is *not* to change the local files. Rather, it changes the state of the index. – William Pursell Nov 22 '16 at 01:44

2 Answers2

0

I have these aliases in my .gitconfig.

# Undo the last commit, but leave it in the working copy
redo = reset --soft HEAD^

# Throw out all work up to the last commit
clear = reset --hard HEAD

# Undo the last commit
undo = reset --hard HEAD^

As you can see, I use reset --soft HEAD^ if I want to do the last commit over. The git-reset docs also mention this use case in their examples. There is an overlap between this and git commit --amend.

Schwern
  • 153,029
  • 25
  • 195
  • 336
0

The use case is for those times when you want to reset the index, but you don't want to change any working files. For example, suppose you've made 3 changes in file foo and done git add foo. Then you realize you don't want to commit all three changes, but you only want to commit one of them. So you do a git reset followed by git add --patch foo to select the hunk you want to commit.

William Pursell
  • 204,365
  • 48
  • 270
  • 300