How to get back <git fetch upstream; git merge upstream / master?
This question differs from other questions in that I want to keep some commits while I return some commits.
Here is 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 that upstream / master has an error and wants to return,
How can I return to the state before the last time I receive / combine upstream?
Change
Let's pretend that
- I leaked upstream
- I combined what the team member clicked on the source / master (personal)
Now I want to cancel step 1.
git reset --hard commit_sha_of_one_prior_the_merge_1
(Although searching for sha is not easy. Git log shows a lot of sha commit upstream, so it's not easy to find commit-sha-of_one_prior_the_merge_1, which is not from
upstream, but fromorigin/master)
How to save the merge of step 2?
Assume a slightly more complex scenario
- I leaked upstream
- I combined what another member of the team clicked on Personal
- I also pushed my work to personal
Now I want to cancel the upward merge. How can i do this?
You can reset the local branch of master to the state of origin/master (if you don't click merge on origin/master ) with:
git reset --hard origin/master If this is not possible, you can use reflog:
git reflog You can see undo git rebase for more details