I have a master branch to which I pushed a commit by mistake. I should have pushed it to a feature branch. So, I have reverted that commit from the master branch, and pushed a revert:
git revert <commit-hash>
git push
Then I have created a new feature branch where I would like to use that commit that I have pushed by mistake to the master branch. I have cherry picked the commit to that branch:
git cherry-pick <commit-hash>
When I do git status, I get:
nothing to commit, working tree clean
Since I would like to make a pull request from that branch, I can't make it without having a commit. How can I make it so that the reverted commit is displayed as a new commit on a feature branch?
CodePudding user response:
After a cherry pick, the working tree is clean, so git status is correct. The cherry pick you just made is the commit you want. So don't worry, be happy. Push your lovely new branch!
CodePudding user response:
You can git revert the reverted commit. A revert creates a new commit that cancels out the reverted commit, and if you revert a revert commit it restores the changes.
Cherry pick may be behaving unexpectedly as the history still contains the commit you're cherry-picking. It sees that commit is already in your branch's history.
Edit: scratch that. If your concern is just that git status is clean then matt's answer is correct. Cherry pick has succeeded and committed the change to your branch (it effectively did the git commit for you--bringing along the changes, message, and other commit metadata).
If you review git log you should see the cherry-picked commit. To checkout the changes from an old commit you could do git checkout SHA_HASH some_file.txt, which would then show it as an untracked change in your working copy.
