Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between git reset --hard HEAD^ vs git reset --hard HEAD? [duplicate]

Tags:

git

github

What does the ^ in git reset --hard HEAD^ do versus just git reset --hard HEAD Is there a difference?

like image 511
ahtmatrix Avatar asked Oct 19 '16 21:10

ahtmatrix


People also ask

What is the difference between git reset and git reset -- hard?

So, in short, we can say that “git reset” is a command, whereas “git reset –hard” is its variation that is used when you want to wipe out all the traces of your last commit.

What does git reset -- hard head do?

Running git reset --hard ORIG_HEAD will let you go back to where you were, but it will discard your local changes, which you do not want. git reset --merge keeps your local changes.

What does git reset head mean?

The git reset HEAD~2 command moves the current branch backward by two commits, effectively removing the two snapshots we just created from the project history. Remember that this kind of reset should only be used on unpublished commits.

What are the types in reset git?

reset --soft : History changed, HEAD changed, Working directory is not changed. reset --mixed : History changed, HEAD changed, Working directory changed with unstaged data. reset --hard : History changed, HEAD changed, Working directory is changed with lost data. It is always safe to go with Git --soft.


1 Answers

HEAD^ is the parent commit of HEAD.

If you want to go into details, then ref^ is the shortcut for ref^1 where ref^1 is the commit's first parent (ref^2 is the commit's second parent, which may be absent if the commit is not a merge commit).

There is also ref~ which is also commit's first parent. It is also a shortcut for ref~1. But the difference between ref^2 and ref~2 is that ref~2 is commit's first parent's first parent. There can be ref~1, ref~2, ..., ref~n (if the history is long enough).

As for the git reset - it resets the current branch to the commit you specify (--hard means to discard both index and working tree changes). git reset --hard HEAD^ resets the current branch one commit backward, while git reset --hard HEAD just discards all local changes.

like image 107
Paul Avatar answered Nov 11 '22 21:11

Paul