I am working on a project where I had made a few changes, committed it and pushed it, however later, I forgot about these changes, soft reset these changes and put them with my next commit, is there anyway I can recover the old commit without affecting the new changes I made? Thanks.
Asked
Active
Viewed 40 times
0
-
"is there anyway I can recover the old commit" Certainly. You pushed it, so it's on the remote and in your remote tracking branch. And it's in the reflog. I'm a little unclear what you want to do with it, or what "without affecting the new changes I made" means, but it is easily recovered. – matt Mar 03 '22 at 03:40
1 Answers
1
Tell me if I got it right. You are on branch X, developed something, committed, then pushed. Then you did a git reset --soft HEAD~
, worked some more and committed again, so you have the previous work with some more work in a single revision that diverged from the revision you already pushed into the remote. Now, you would like to get this revision kind of on top of the first revision you committed/pushed?
git reset --soft origin/X
git commit -m "only the changes from second revision"
Adjust the name of the remote branch and it should work.