December 2021
git reset --soft HEAD~;
It is not uncommon to commit
(but not push
) all the files I have staged, then realize either (a) I didn't mean to do that or (b) a co-worker has pushed a change to the PR we're working on and I'm not interested in creating a merge commit 😬.
So I run the above to walk back the commit, then I run git restore --staged .
to unstage all those changed files, and then I re-build my commit(s) as needed.
Update 15-July-2016
Still wrecking things in git! 😀 But now I'm mostly making notes over in issues as a breadcrumb trail. Feel free to add your own busted-then-fixed situations! ✨
For a long time: when I encountered merge conflicts and non-fast-forward errors with git at work, my SOP was to freak. right. out.
And in past-me's defense, 99% of the time this had zero impact on anyone else, so my preferred solution of blowing away the branch and starting over worked just fine. Of course, I finally accepted this was kind of a terrible way to behave—or anyway, it wouldn't scale—and decided to teach myself more productive responses to branchname|CONFLICT
.
I made a repo at work where I set about trying to induce the errors and weirdo messages that make me so nervous. It worked really well! (I even had a rebase-squash that put me through 5 rounds of merge conflicts like a champ.) And then I deleted the repo.
Way to go, me! …
So I'm doing it again in the name of practice and with the hope that perhaps it'll be useful to someone else as well.
- Git Immersion
- git ready
- Think Like a Git (disclosure: I work with Sam)
- git