jtr13
jtr13

Reputation: 1277

Difference between git reset --hard HEAD~1 and git reset HEAD~1 --hard?

To the best of my understanding git reset --hard HEAD~1 and git reset HEAD~1 --hard do the same thing, employing different forms of git reset:

git reset [<tree-ish>] [--] (first form in the git reset help file)

git reset [--] [<commit>] (third form)

Is this correct? Is one preferred over the other?

Upvotes: 1

Views: 97

Answers (1)

alfunx
alfunx

Reputation: 3140

Have a look at the full synopsis:

git reset [-q] [<tree-ish>] [--] <paths>…​
git reset (--patch | -p) [<tree-ish>] [--] [<paths>…​]
git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]

In the first two forms, you are not allowed to use the --hard flag. Both of your commands will thus refer to the last form. The Git CLI allows you to re-order flags for convenience — as long as there's no ambiguity.

Upvotes: 2

Related Questions