2

I already pushed a commit to a remote branch. There is any way to change that commit pushed to another remote branch.

git push <remote> <branch>

can I use the cherry pick for copying the commit to another branch?

Amjad Rehman A
  • 788
  • 10
  • 21
  • 1
    Does the answer helps you solve the problem? If yes, can you mark the answer by clicking √ symbol on the left of the answer? And it will also benefit other members who meet similar questions. – Marina Liu Jul 16 '18 at 08:56

1 Answers1

3

If you really pushed to the wrong remote branch, then you probably have to first undo that push, at least logically, and then do a second push to the correct branch. So something like this:

# undo first commit to wrong branch2
git checkout branch2
git pull origin branch2
git revert <SHA-1 of commit from branch1>
git push origin branch2

# now push to correct branch
git checkout branch1
git push origin branch1

I used git revert to undo your unwanted commit to branch2, assuming that this branch is already publicly shared. Reverting a commit is the safe way to proceed in this situation.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360