Corey Hart
Corey Hart

Reputation: 10596

git backout master, push to branch, to go into master at later date

How would I go about:

1) Reverting changes pushed out to master (remote)
2) Moving those changes to a separate branch
3) Move those changes back into master at a later time

Upvotes: 2

Views: 505

Answers (2)

Cameron Skinner
Cameron Skinner

Reputation: 54306

Assuming you have already cloned the remote repo and you're on the master branch, you could do the following:

Do the second thing first:

git branch new-branch

Then revert changes on master:

  1. git revert <commit-id-you-want-reverted> (repeat for each bad commit)
  2. git push origin HEAD:master

Later, cherry-pick them back:

git cherry-pick <commits-from-new-branch>; git push origin HEAD:master

I think that'll work, but I haven't tried it myself. YMMV. I think simply pulling the changes back (without cherry-picking) won't work because they'll have the original commit IDs and git might know that it doesn't need to pull them in...then again, maybe with a new HEAD it will work. Try it and see :)

Upvotes: 0

Fred Foo
Fred Foo

Reputation: 363567

First do 2), but only if you really need the branch.

git branch changes

Then do 1) using git revert.

Finally, redo the changes by reverting the revert commits.

Upvotes: 3

Related Questions