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)?
Asked
Active
Viewed 2,502 times
2

zero
- 2,999
- 9
- 42
- 67
-
how exactly did you use `git revert`? – Konstantin Apr 16 '15 at 17:34
-
`git revert
` – zero Apr 16 '15 at 17:35 -
There are many ways of doing this. You could cherry-pick the commit onto your branch, or you could check out your branch and revert the revert commit. – user229044 Apr 16 '15 at 17:38
2 Answers
5
I suggest to cherry-pick
your commit to a new branch (if reset isn't possible):
- Run
git log
and copy the commit hash (which wasn't reverted yet) git checkout
to a new branch- Run
git cherry-pick <copied-commit-hash>
You will get new commit with different hash.

peresleguine
- 2,343
- 2
- 31
- 34
-
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
-
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.
-
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