This project has only a master
branch, so all work is being done there.
I mistakenly committed a typo, and while I could commit an undo, I thought I'd try just removing the commit altogether.
The commit hash is dbcbf96b
, and ded82215
is the commit right before it. So, working from these instructions, I did this:
git rebase -i ded82215
This brought up the "todo" list in an editor, containing only the following, as expected:
pick dbcbf96 Writer update.
Presumably following the instructions in the comments of that generated file, I changed that line to:
drop dbcbf96 Writer update.
I saved the file and closed the editor. It then said:
Successfully rebased and updated refs/heads/master.
I then checked on GitLab (what I'm using to host this) expecting to see the commit gone, but it was not, it was still there.
I did
git status
to see what action it recommended and it yielded:On branch master Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) nothing to commit, working tree clean
That kinda makes sense, but as for the rebase, I'm not sure what happened. Now I did
git pull
to update the local repo but it was all just right back where I started, right back atdbcbf96b
with the local file still containing the change, the local repo up to date, and GitLab still showing the revision. Thepull
command yielded:Updating ded8221..dbcbf96
So my rebase attempt did nothing at all. What did I miss here?
So I tried git push -f
between steps 4 and 5 as recommended by the answer below and it failed, yielding:
Total 0 (delta 0), reused 0 (delta 0)
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To https://gitlab.com/...
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/...'
I then tried git push
just for grins and it also failed, yielding:
To https://gitlab.com/...
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitlab.com/...'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
That kind of makes sense, too, I suppose that's what -f
is for. The hints in the second bit again recommended git pull
, which I already know isn't the right action here.