threads / discuss / 13499

abouy git reset command

Subject: abouy git reset command

## tl;dr

3 messages between May 13, 2008 and May 13, 2008.

replies: 2people: 3as markdown or json

amishera· May 13, 2008, 07:07 UTC · lore

Hi, I just want to make sure whether my understanding of that command is correct or not. I have 3 basic requirements:

1. I have changed something after the commits and I think those are wrong.
So I want to undo all changes and the working directory should reflect last
commit:
git reset --hard HEAD
2. I have some changes in the index and I want undo them.
git reset HEAD
3. I just want to undo the last commit but not the working tree:
git reset HEAD^
If they are correct commands please let me know. 
Besides in the man page for git reset it is mentioned:
git-reset - Reset current HEAD to the specified state

Which means it is supposed to work with commits. But why is the same command work in case 2 and case 3 above?

Moreover, can any body tell me the use of
git reset --soft
The following language is confusing:
--soft
    Does not touch the index file nor the working tree at all, but requires
them to be in a good order.
Thanks in advance.
-- 
View this message in context: http://www.nabble.com/abouy-git-reset-command-tp17202423p17202423.html
Sent from the git mailing list archive at Nabble.com.
Jakub Narebski· May 13, 2008, 08:33 UTC · re: amishera · lore

Re: abouy git reset command

amishera <amishera2007@gmail.com> writes:
Show 16 quoted lines
> I just want to make sure whether my understanding of that command is correct
> or not. I have 3 basic requirements:
> 
> 1. I have changed something after the commits and I think those are wrong.
> So I want to undo all changes and the working directory should reflect last
> commit:
> 
> git reset --hard HEAD
> 
> 2. I have some changes in the index and I want undo them.
> 
> git reset HEAD
> 
> 3. I just want to undo the last commit but not the working tree:
> 
> git reset HEAD^
If you mean by "undo last commit" reset HEAD pointer and index state,
then yes.
 
Show 19 quoted lines
> If they are correct commands please let me know. 
> 
> Besides in the man page for git reset it is mentioned:
> 
> git-reset - Reset current HEAD to the specified state
> 
> Which means it is supposed to work with commits. But why is the same
> command work in case 2 and case 3 above?
> 
> Moreover, can any body tell me the use of
> 
> git reset --soft
> 
> The following language is confusing:
> 
> --soft
> 
>     Does not touch the index file nor the working tree at all, but
>     requires them to be in a good order.

git-reset is all about setting the HEAD pointer, or to be more exact to set current branch (current head) reference. There are three degrees of it:

 --soft changes only current HEAD
 --mixed (default) changes current HEAD and index file
 --hard changes current HEAD, index file and working tree

If you don't give <commit-ish>, git-reset defaults to HEAD, i.e. current version. Thus "git reset --soft" is no-op, it does do nothing.

-- 
Jakub Narebski
Poland
ShadeHawk on #git
David Tweed· May 13, 2008, 12:34 UTC · re: amishera · lore

Re: abouy git reset command

On Tue, May 13, 2008 at 8:07 AM, amishera <amishera2007@gmail.com> wrote:
> Moreover, can any body tell me the use of
>
> git reset --soft

Jakub answered about "git reset --soft" on its own, so I'll just mention the situation I use, say, "git reset --soft HEAD~5" which is: suppose you realise that you made a really bad mistake 5 commits ago (say some obscure bug that could cause data loss) and you've just discovered and fixed it in your working tree (checking in bits to the index). You don't want to risk ever running a version of your program built from any of those commits. What you really _ought_ to do is essentially redo those 5 commits removing the bug, but depending how rigorous and time constrained your development is you might just want to commit your new fixed state with one big change log. "git reset --soft HEAD~5" moves HEAD back five commits but leaves your working tree and index alone, so the next "git commit" will commit your fixed current state after the new HEAD. It's clearly not what you want to do if you're working in a careful development team, but I find it useful on rare occasions.

-- 
cheers, dave tweed__________________________
david.tweed@gmail.com
Rm 124, School of Systems Engineering, University of Reading.
"while having code so boring anyone can maintain it, use Python." --
attempted insult seen on slashdot

← back to recent threads