Edit: what's below is wrong -- the workflow on @b0rk_rerunsJulia's Reruns Bot's "Oh Shit, Git" site is indeed symmetric for making a commit to the wrong branch. I'm considering a PR to clarify that.

For posterity, my erroneous question is below. I think I got confused because, in the second example, I wasn't switching branches the way I thought I was...

--------------------

Git folks: I'm looking at @b0rkJulia Evans's Oh Shit, Git thing for when you commit to the wrong branch and want to move the top commit elsewhere.

For a commit to main, you have:

# create a new branch from the current state of master
git branch some-new-branch-name

# remove the last commit from the master branch
git reset HEAD~ --hard

# move to the new branch
git checkout some-new-branch-name

That works. But if the original branch isn't main, it doesn't. I don't understand why: main is just another branch, right?

When I do the above while on the topic1 branch, the commit just goes away. (Well, it's in the reflog.) Why didn't it do that when I was on main?

0

If you have a fediverse account, you can quote this note from your own instance. Search https://mathstodon.xyz/users/ddrake/statuses/115633967836101201 on your instance and quote it. (Note that quoting is not supported in Mastodon.)