threads / discuss / 16975

git reset --hard <commit> superfluous?

Subject: git reset --hard <commit> superfluous?

## tl;dr

3 messages between Jan 3, 2009 and Jan 3, 2009.

replies: 2people: 3as markdown or json

chris@seberino.org· Jan 3, 2009, 01:13 UTC · lore
David

git reset --hard <commit> "resets" the current branch head.

Is this equivalent to deleting the branch and doing

git branch <branch> <commit> ??
So "git reset --hard" is syntactic sugar and 'unnecessary' right?
cs
Sitaram Chamarty· Jan 3, 2009, 06:34 UTC · re: chris@seberino.org · lore

Re: git reset --hard <commit> superfluous?

On 2009-01-03, chris@seberino.org <chris@seberino.org> wrote:
Show 9 quoted lines
> git reset --hard <commit>
> "resets" the current branch head.
>
> Is this equivalent to deleting the branch
> and doing
>
> git branch <branch> <commit> ??
>
> So "git reset --hard" is syntactic sugar and 'unnecessary' right?

only if you don't have any local changes to the work tree or the index :-)

If you do, however, the reset throws them away, while the longer method tries to preserves them, to the point of not letting you switch if there are too many changes.

Björn Steinbrink· Jan 3, 2009, 12:20 UTC · re: chris@seberino.org · lore

Re: git reset --hard <commit> superfluous?

On 2009.01.02 17:13:19 -0800, chris@seberino.org wrote:
Show 11 quoted lines
> David
> 
> git reset --hard <commit>
> "resets" the current branch head.
> 
> Is this equivalent to deleting the branch
> and doing
> 
> git branch <branch> <commit> ??
> 
> So "git reset --hard" is syntactic sugar and 'unnecessary' right?

Deleting the branch also deletes the reflog, while using reset adds a new entry to the reflog. So returning the branch head to its previous state is pretty trivial if you used reset and might be pretty hard if you deleted the branch. HEAD's reflog should probably have the right entry as well, but chances are that it's hidden in a crapload of other entries, especially if you rebase often.

Björn

← back to recent threads