Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117301

How to revert commits without loosing changes?

I just realized that the last three commits i have made have been against the master branch.

enter image description here

I know I could do a

Git reset --hard

I tried a

Git reset --soft 

but it doesn't seam to have done anything.

I need to get these changes uncommitted so that i can move them to their own branch. I am desperate not to loose all of these changes. I cant push to master without a code review so i need to get these changes out of the master branch and into their own.

Upvotes: 1

Views: 76

Answers (1)

Romain Valeri
Romain Valeri

Reputation: 22067

Your git reset --soft was the right way, but you also have to point to the right commit, and after the reset you're not completely done yet.

# reset to the commit BEFORE (^) the first bad one
git reset --soft 274c94^

At this point, the modifications described in the three "bad" commits we've just undone are in your working tree, waiting to be added and committed

# then switch branch to whichever branch suits your needs
git checkout myBranch

# Add and commit the way you usually do, for example :
git add .
git commit -m "Awesome message"

Upvotes: 3

Related Questions