This question is different from other questions in that, I want to keep some commits while I revert some commits.
Here 's my setup.
Upstream repo on github (public repo which I don't own)
Personal repo on my server(git clone --bare $upstream)
My workflow was like this:
Need to customize my personal branch
1. check out origin/master(Personal)
2. make changes
3. push to origin/master
Need to get new feature or bug fix from the original author(github)
1. git fetch upstream
2. git merge upstream/master
Now I find upstream/master has a bug and want to revert,
How do I go back to the state before I fetch/merged upstream for the last time?
Edit.
Suppose
- I merged upstream
- I merged what a team member pushed to origin/master(Personal)
Now I want to undo the step 1.
git reset --hard commit_sha_of_one_prior_the_merge_1
(Although finding the sha is not easy. git log shows a lot of commit sha's of upstream, so it's not easy to find commit-sha-of_one_prior_the_merge_1 which is not of
upstream
but oforigin/master
)
How do I keep the step 2 merge?
Suppose a slightly more complex scenario
- I merged upstream
- I merged what another team member pushed to Personal
- I also pushed my work to Personal
Now I want to undo the upstream merge. How can I do it?