A tale born through some hot tears at work... I had made a *temporary commit* on feature branch *A*, that I wanted to put directly in the *master *(main) branch, as it was not related to the feature.
However, I had a lot of unstaged changes (read: 10+ hours of work) that I didn't want to stash and cause Eclipse to refresh & rebuild. So my "incredibly smart" idea was to cherry pick that commit onto the master, then *git reset --hard HEAD^* to remove the unrelated commit from the feature branch. I foolishly thought that this would only remove the commit and leave any local changes alone. With Eclipse suddenly greeting me with a lot of "method xyz is undefined" errors, I noticed that a lot of changes had simply vanished, and all that was left in my git status were the newly created, untracked files. Some digging around git reflog and subsequent desperate googling informed me of the following: *"The git reset –hard command will revert uncommitted changes that exist in files that have been added to the index, whether those files are newly created files, or files that were added to the index in the past and have been edited since the last commit. However, if any new files have been created in the Git repository that have never been added to the index, these files will remain in the project folder after the hard reset."* ( source <https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/remove-revert-discard-local-uncommitted-changes-Git-how-to> ) In other terms: if you run git reset --hard, any modification that was not staged, stashed or committed will be IRREVERSIBLY lost. Maybe some of you will now think "yeah, duh". Well, I did not know that. I personally would have really wished that git had informed me of this, e.g. by prompting me to confirm with a notice of the effect. Perhaps it would be expected of me to be 100% aware of what git reset --hard does, and this is simply a case of "learning it the hard way". I genuinely do not know. Before submitting this as a feature idea, I was moved to post my dilemma here first to see if it would find any support. Thank you for taking the time to read this far, you rock :) -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/git-users/9b86773d-586c-472d-b6d5-6d0ba68e3756n%40googlegroups.com.
