Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What command did git do with "git reset --har"

Tags:

git

I missed the tab key before pressing enter on my local git branch, I ended up executing:

git reset --har

versus the intended

git reset --hard

Usually git complains when running a command that appears to be mistyped. I looked through the --help for git reset and found no args for "h","a","r".

It seems to have run the hard reset, What did it actually run? Or if it ran "--hard" why?

additional info: sylvesterjakubowski$ git --version git version 1.7.12.4 (Apple Git-37) #on mountain lion.

like image 747
sjakubowski Avatar asked Aug 15 '13 16:08

sjakubowski


People also ask

What does git reset -- hard command do?

Summary. To review, git reset is a powerful command that is used to undo local changes to the state of a Git repo. Git reset operates on "The Three Trees of Git". These trees are the Commit History ( HEAD ), the Staging Index, and the Working Directory.

What does the command git reset -- hard head 3 do?

git reset changes where the current branch is pointing to ( HEAD ). HEAD is a pointer or a reference to the last commit in the current branch. HEAD~3 would mean behind three commits from HEAD . Assuming HEAD is pointing to C3 and the index (stage) matches to C3 .

What would happen if you ran the git reset?

It resets the index, but not the work tree. This means all your files are intact, but any differences between the original commit and the one you reset to will show up as local modifications (or untracked files) with git status.


2 Answers

This is as per the gitcli doc page:

many commands allow a long option "--option" to be abbreviated only to their unique prefix (e.g. if there is no other option whose name begins with "opt", you may be able to spell "--opt" to invoke the "--option" flag), but you should fully spell them out when writing your scripts; later versions of Git may introduce a new option whose name shares the same prefix, e.g. "--optimize", to make a short prefix that used to be unique no longer unique.

Also on the same page:

Commands that support the enhanced option parser accepts unique prefix of a long option as if it is fully spelled out, but use this with a caution. For example, git commit --amen behaves as if you typed git commit --amend, but that is true only until a later version of Git introduces another option that shares the same prefix, e.g `git commit --amenity" option.

So yeah, it ran git reset --hard

like image 121
manojlds Avatar answered Sep 29 '22 11:09

manojlds


It did not run the equivalent of -h -a -r because there are two preceding dashes, not one.

Git may be implementing an algorithm here to allow you to use the shortest unique match for a long flag name. Since no long flags for git reset start with --har, it could have then treated the request as unambiguous and proceeded to run git reset --hard.

like image 41
Mark Stosberg Avatar answered Sep 29 '22 11:09

Mark Stosberg