I use git in a fairly linear and basic manner, but I ran into an issue that I rarely run into and I am unsure of how to fix.
I committed something too early in one of my branches. It will get launched soon, but I am not ready to have it launched yet. I am trying to figure out the best way to go about having the branch I am working on point to a previous commit before I merge this branch into the master branch, so that when this branch is merged into the master branch it is not referencing the most recent commit.
Using git log (git log --oneline
), I have the following:
d17be71 (HEAD -> qa, origin/qa) Fix footer in jsp.
bc6dde8 (featureBranch1) Correct company logo.
So d17be71
was accidentally added to qa, and qa will be merged into master. I don't want these changes to be merged into master, but I don't want to lose them. I want bc6dde8
to be merged into master, and after this code launches successfully, then I will incorporate d17be71
back into qa, then merge that into master, then launch that as well.
Doing some reading on merging, branching, and HEAD
:
But I'm still a little lost as to what the correct approach should be. I am assuming that I can just point the HEAD
to bc6dde8
, and that will act as the last commit so that when I merge into master, d17be71
will not be merged into master but still exist on my qa branch, but I haven't read anything that confirms this will actually happen.
I guess I could create a new branch off of qa, then go back to qa and revert back to bc6dde8
and erase my last commit, then merge back into qa after launching, but I am assuming I don't have to do that. Just having a difficult time figuring out what exactly it is I am supposed to do if not that.
How should I go about correcting this mistake?
You could simply git revert d17be71
. It won't erase d17be71
, but instead generating a reverting commit that essentially cancels out d17be71
. Make a note of the hash of that reverting commit. After qa
is merged into master
, run another git revert the-revert-commit-hash
, it'll cancel out the revert, and effectively reinstate the d17be71
changes.