2

I used git revert to undo changes that were committed and pushed to my dev branch (this is my first time using this command) and everything went smoothly, but I need to know if it's possible to: keep dev the way it is, but get back those changes temporarily and then add them to a new branch (don't wanna work on dev with this)?

zero
  • 2,759
  • 7
  • 38
  • 56

2 Answers2

5

I suggest to cherry-pick your commit to a new branch (if reset isn't possible):

  1. Run git log and copy the commit hash (which wasn't reverted yet)
  2. git checkout to a new branch
  3. Run git cherry-pick <copied-commit-hash>

You will get new commit with different hash.

Read more about cherry-pick

peresleguine
  • 2,203
  • 2
  • 28
  • 31
  • is there an advantage to having a new hash assigned? I wonder because this code will get merged back to dev at some point (still trying to get a grasp on how git works) – zero Apr 16 '15 at 17:41
  • I think there is. Basically you need a revert of a revert to keep history understandable. So it should be the new commit. – peresleguine Apr 16 '15 at 17:48
  • After merge your changes will look reasonable: committed -> reverted -> committed again. – peresleguine Apr 16 '15 at 17:56
  • yeah I want to keep the history has healthy as possible – zero Apr 16 '15 at 18:15
1

this worked perfectly: How do I create a new git branch from an old commit?

just checking it out as part of a new branch creation. this was very simple.

Community
  • 1
  • 1
zero
  • 2,759
  • 7
  • 38
  • 56
  • Disadvantage to this approach: if you then merge with dev (in either direction) the revert commit will be part of the merge, and at best give you conflicts or at worst undo those changes again. Reverting the revert would protect you from this – ComputerDruid Apr 16 '15 at 17:51