git reset HEAD~1

Cláudio Silva claudiodcsilva at gmail.com
Mon Feb 13 17:49:37 UTC 2012


I think the hyphen does not exist in git. You have carrot (^) and
tilda(~). The difference is that tilda(~) is used for a linear history
whereas the carrot(^) is able to follow commits with multiple parents.

The following syntax applies:
HEAD^(parallel parent number)
HEAD~(linear ancestor number)

E.g.
 If you have a commit A which has two parents B and C (someone screwed
up with a merge). Also consider a D that is B's parent:
HEAD = A
HEAD^ == HEAD^1 = B (1st parent)
HEAD^2 = C (2nd parent)
HEAD^3 = N/A (only two parents)

HEAD~ = B
HEAD~2 = D (parent of the first parent) = HEAD^^1 = HEAD^1^1

HEAD^2^1 would yield the (first) parent of C. This notation is
impossible using only tilda~

The following equivalences apply:
HEAD = HEAD
HEAD^ = HEAD~
HEAD^^ = HEAD~2
HEAD^^^ = HEAD~3
...

Both syntaxes can be stacked:
HEAD~3^2 - (second parent of the third previous commit)

(sorry for the mess, just trying to explain)

Regards,
Cláudio

On Mon, Feb 13, 2012 at 5:10 PM, Gedare Bloom <gedare at rtems.org> wrote:
> I've updated the wiki with these new examples. I think there is a
> difference when you use a ~ (tilda) and a - (hyphen). Now the wiki
> avoids using hyphens.
>
> On Mon, Feb 13, 2012 at 10:22 AM, Cláudio Silva
> <claudiodcsilva at gmail.com> wrote:
>> Hi,
>>
>> I think that description is wrong. Let's try a longer description
>> (hopefully correct) of git reset:
>>
>> "git reset HEAD~" will undo the last commit and unstage those changes.
>> Your working directory will remain the same, therefore a "git status"
>> will yield any changes you made plus the changes made in your last
>> commit. This can be used to fix the last commit. You will need to add
>> the files again.
>>
>> "git reset --soft HEAD~" will just undo the last commit.The changes
>> from last commit will still be staged (just as if you finished git'
>> adding them).  This can be used to amend the last commit (e.g. I
>> forgot to add a file to the last commit).
>>
>> "git reset --hard HEAD~" will revert everything, including the working
>> directory, to the previous commit. This is dangerous and can lead to
>> you losing all your changes.
>>
>> "git reset HEAD" will unstage any change. This is used to revert a
>> wrong git add. (e.g. I added a file that shouldn't be there, but i
>> haven't 'commited')
>>
>> "git reset --hard HEAD" will revert your working directory to a HEAD
>> state. (You will lose any change you made to files after the last
>> commit). This is used when you just want to destroy all changes you
>> made since the last commit.
>>
>> Regards,
>> Cláudio
>>
>> On Mon, Feb 13, 2012 at 2:13 PM, Ralf Corsepius
>> <ralf.corsepius at rtems.org> wrote:
>>> Hi,
>>>
>>> http://wiki.rtems.org/wiki/index.php/Git
>>>
>>> tells:
>>>
>>>  git reset HEAD-1
>>>
>>> Removes the last 1 (or any other number you put) commit from the current
>>> branch. git reset should only be used on local branches that no one else is
>>> accessing remotely. This is a very powerful and tricky command; A good
>>> description of what it enables to do can be found here
>>>
>>>
>>> Either there is a language barrier causing me to misunderstand this sentence
>>> or this sentence doesn't seem right:
>>>
>>> git reset HEAD  ... removes the last commit
>>> git reset HEAD~1 ... remove the last 2 commits
>>>
>>> The human factor had just hit me (I needed to revert my last commit),
>>> causing me to exercise this to trip over this.
>>>
>>> Ralf
>>>
>>>
>>> _______________________________________________
>>> rtems-devel mailing list
>>> rtems-devel at rtems.org
>>> http://www.rtems.org/mailman/listinfo/rtems-devel
>>
>> _______________________________________________
>> rtems-devel mailing list
>> rtems-devel at rtems.org
>> http://www.rtems.org/mailman/listinfo/rtems-devel




More information about the devel mailing list