Reputation: 643
On origin, I have 2 branches: master
and development
.
master
is ahead of development
by a few commits and behind by a few commits.
I want the tree of master
branch to be identical to the one of development
branch (talking about the tree object of the revisions, not the history, actually). It is fine if I lose anything on the master
branch, but the development
branch should be intact.
Reasons for doing this is, we have a workflow where we work on development
and merge to master
when we are ready to do a release. Over time there have been some commits made directly to master
. We want to bring master
back in sync with development
.
Can you please share how this can be achieved? One way which I think might work is merge master
to development
, then revert the commit from the merge in development
, and merge development
to master
.
Edit: I cannot force push. I need to create a pull request to make any changes.
Upvotes: 1
Views: 825
Reputation: 1781
What you have encountered is a standard Git development problem that we all run into, and because of that a branching methodology has been created. Some branching strategies are more popular than others. The 3 most popular are:
GitFlow (what it seems like you need): https://nvie.com/posts/a-successful-git-branching-model/
GitHub Flow: https://guides.github.com/introduction/flow/index.html
I'm going to quickly describe how to solve your issue:
This is how to solve your issue going forward:
Upvotes: 0
Reputation: 30212
just push development into remote master (even if by using -f to force it):
git push -f origin develop:master
Adjust name of remote.
Another hackish suggestion
If you want to have master look exactly like develop with a PR with the least amount of work possible, this is what you would want to do:
git cat-file -p origin/develop # find the ID of the _tree_ of this revision
git commit-tree -p origin/master -m "Tree of master is now just like develop" id-of-tree-of-last-command # create a new revision with the same tree of develop... this will generate one ID
git checkout -b some-development use-id-printed-by-commit-tree
git push some-remote some-development
Now you can create your PR from some-development.... if you also want develop to be a parent of this revision, add it as another -p parameter to commit-tree.
Upvotes: 4