1

I have a change that I commited to my master branch. Other devs have also merged other feature branches into master after I made my commit. How would I revert master to a commit before mine and then merge only my change into master?

Right now I was planning to do these steps:

git checkout master
git reset --hard e3f1e37 
git push --force origin master

and then I would want to cherry-pick my change in. However, the branch that had my change has been deleted and only exists in the current master. Is there a way I can still cherry-pick this in?

DannyD
  • 2,732
  • 16
  • 51
  • 73

1 Answers1

1

You can check git reflog for log of commits. By searching through the list of commits you should be able to pick those which you need and simply cherry-pick them.

For example your reflog will look like this

user$ git reflog
c9f9669 HEAD@{0}: commit: Fixed test cases to run on Unix
b3ca8a4 HEAD@{1}: pull: Fast-forward
54ba188 HEAD@{2}: pull origin master: Fast-forward
e659a21 HEAD@{3}: reset: moving to HEAD~1
12944d8 HEAD@{4}: reset: moving to HEAD~1
6f40152 HEAD@{5}: reset: moving to HEAD~1
3de61ba HEAD@{6}: pull: Fast-forward
e659a21 HEAD@{7}: reset: moving to HEAD^1
12944d8 HEAD@{8}: reset: moving to HEAD^1
6f40152 HEAD@{9}: reset: moving to HEAD^1
3de61ba HEAD@{10}: commit: Removed Query object
6f40152 HEAD@{11}: pull: Merge made by the 'recursive' strategy.
12944d8 HEAD@{12}: commit: API touchups
e659a21 HEAD@{13}: commit: Test enhancements
07419e1 HEAD@{14}: pull: Fast-forward

The commits that you're looking for are ones with hash 3de61ba and 12944d8

git cherry-pick 3de61ba
git cherry-pick 12944d8

It should be pretty simmilar to what you need.

More info on how the reflog works and how to use it you can find in the official Git documentation

Kamil
  • 2,712
  • 32
  • 39