Reputation: 23921
I forked a project on github, made a new branch and made some changes (commits B, C and D) so I had the following tree:
... <-- A (master)
\
B <-- C <-- D (branch2)
I mistakenly merged and deleted branch2
so now I had this tree:
... <-- A <-- B <-- C <-- D (master)
However, I realized that I want to maintain a master branch that reflects the upstream changes and created myproject-master to have my work on that. I moved my commits by rebasing them to that new branch. After rebasing I deleted the <-- B <-- C <-- D
part from the history on master by git reset --hard "A"
. I also squased C
and D
and I'll refer to that commit as CD
from now on. My problem is that I can't push my changes on master and I have different trees in local and remote:
This is the local tree (what I want to have on both sides):
... <-- A (master)
\
B <-- CD (myproject-master)
This is the remote tree:
... <-- A <-- B <-- C <-- D (master)
\
B <-- CD (myproject-master)
When I try to push on master, git rejects the push so I don't lose data. Which is fine, but I already have those commits on the other branch and would like to clean them from the master. How can I do this?
Upvotes: 1
Views: 472
Reputation: 467033
If you are the only person working on the repository, it's safe to do a "force push" of your master branch to the remote repository, e.g. with:
git checkout master
git push -f myrepo master
... but since that's rewriting the history of the master branch, you will have to be more careful if you have any collaborators who have already pulled your master
when it was ahead of A
.
Upvotes: 2