The mistake:
I git rebase -i --root
'ed my branch, ignorantly thinking I could reword the first commit differing from the master (the GitHub for Windows default view is the comparison to master, hiding it's entirety).
I grew a Silicon Valley beard while 900+ commits loaded themselves into Sublime. Exiting with no changes, I charged my battery then proceeded to shave, as all 900+ individual commits nonchalantly rebased - resetting their commit times to now.
Determined to beat Git and preserve the original times, I deleted this local repository and re-cloned from the remote.
Now it had re-added a most recent unneeded commit to master I wished to remove, so proceeded like so.
Exhausting the options:
I didn't wish to git revert
- it would create an additional commit, giving Git the upper hand.
git reset --hard HEAD
did nothing, after checking the reflog
, the last and only HEAD
was the clone - Git wins.
To get the most recent SHA, I checked the remote repository on github.com - minor win.
After thinking git reset --hard <SHA>
had worked, I updated another branch to master and 1... 2... poof! the commit was back - Git wins.
Checking back out to master, time to try git rebase -i <SHA>
, then remove the line... to no avail, sad to say. "If you remove a line here THAT COMMIT WILL BE LOST". Ah...glossed over new feature troll the n00b in the 2.8.3 release notes.
The solution:
git rebase -i <SHA>
then d, drop = remove commit
.
To verify, I checked out to another branch, and voila - no hiding commit to fetch/pull from the master.
https://twitter.com/holman/status/706006896273063936
Good day to you.
cherry-pick
anddelete
a single commit that may occurred a while ago. – Chrisgit rebase -i HEAD~10
does address the question, as it does let you arbitrarily pick commits to delete. Git applies the commits in the range you specify one-by-one, ignoring commits you have removed from the log. I used this command today to get rid of the second and third most recent commits to my repo while keeping the top one. I agree that none of the other answers are satisfactory. – MSTgit reset --soft HEAD~1
is exactly what you need. In such case you will undo commit and save your work.reset --hard
will remove commit completely. – sergpank