I checked in a few commits to master
that should have been checked into develop
. What git commands do I used to remove those commits from the master branch and include in the develop branch?
git cherry-pick <commit-hash> will apply the changes made in an existing commit to another branch, while recording a new commit. Essentially, you can copy commits from branch to branch.
If I'm not mistaken, you had two synchronized branches, master
and dev
, and simply forgot to switch the branch, before your commits.
If that is the case, we have:
---------------- git log in dev xxx yyy ... ----------------
and:
---------------- git log in master ccc bbb aaa <---- here you forgot to switch branch xxx yyy ... ----------------
The solution is:
First, make sure, that:
git status -s
returns empty results.
Next, get all your new commits from master
to dev
with:
git checkout dev git merge master
Now return to you master
:
git checkout master
Remove unnecessary commits:
git reset --hard HEAD~3
The number ~3
is the number of commits you want to remove.
Remember: git status -s
have to return empty results. Otherwise, git reset --hard
can cause data loss.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With