Skip to content

--hard should have caveat because Google #2

@cefn

Description

@cefn

Unfortunately, in spite of your detailed explanations, Google has chose to deep-include a fragment of your guide which is very misleading.

When I search for 'git undo last commit' it provides a snippet of your page out of context http://sethrobertson.github.io/GitFixUm/fixup.html as follows...

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.

Unfortunately if learners are trying to remove the last commit from git, this actually guides them to delete their work, rather than removing the commit so they can redo it.

Of course this is detailed in your comments...

Strongly consider taking a backup of your current working directory and .git to avoid any possibility of losing data as a result of the use or misuse of these instructions. We promise to laugh at you if you fail to take a backup and regret it later.

However, perhaps you are confident (or arrogant) enough to know for sure that you will never ever want the uncommitted changes. If so, you can run git reset --hard, however please be quite aware that this is almost certainly a completely unrecoverable operation. Any changes which are removed here cannot be restored later.

However, if they do not read through the whole of your document and read this snippet directly as is highly likely, then the contribution of this paragraph will be to cause possibly many tens of thousands of people to lose their work, since it's the first hit on Google.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions