I made a new branch to tinker with code without messing up the main branch I was working on. It ended up bearing no fruit, so I went back to working on the parent branch without bringing any of the changes. There is a single commit made on the new branch, but I want it off the commit history!
The commit was pushed to a remote repo, so there is an origin pointer on it. I'm not sure if that has anything to do with it. Help!
git rebase -i <commit id>
did nothing for me, only prompted me to modify the newer branches. I've tried running it while on the branch the commit was made on, and while on the parent branch.
The commit was pushed to a remote repo, so there is an origin pointer on it. I'm not sure if that has anything to do with it. Help!
Yes – think of those as two semi-separate branches; the "origin pointer" represents a remote branch of the same name. So you have to delete the commit from your local branch and push the update to the corresponding remote branch (which also updates your local 'origin' pointer for it).
I don't think a rebase is really of any use here. You have no need for rewriting any commits, like what would be necessary when removing a commit from the middle – the d9e7124
doesn't chain off the unwanted commit – the ones you're deleting aren't referenced by anything else except the branch pointer, and so can be chopped off the end just by updating the branch pointer alone.
So if the branch is currently checked out and you want to roll it back:
git reset [--keep] d076a2e
Without any options, the changes from that commit will return to being uncommitted changes. Adding --keep
will throw away the changes that got committed, but keep the uncommitted ones as-is. Using --hard
will throw away the changes that were committed and the uncommitted changes, returning all files exactly to the specified commit.
On the other hand, if you're currently on a different branch (e.g. back on main/master), you can re-create the side branch; optionally specifying a different starting point:
git branch --force BranchName [starting_point_commit]
-or-
git branch --delete BranchName
Either way, the update needs to be force-pushed to the remote – or you can push a branch deletion if you no longer want it on the server.
git push --force origin BranchName
-or-
git push --delete origin BranchName
The 136b98c
commit ID will linger in your repository's storage for a while (so it is possible to re-attach it to a branch if necessary), but eventually it'll be garbage-collected after a few weeks.