问题
At the beginning the local branch is uptodate and now I use git rebase -i HEAD~3
and modify the pick
of the two newest commits to fixup
to combine 3 commits at the local branch,and now I want to push the local branch to the remote. And I only want to show a combined commit at the remote.
However,after combined the local branch falls behind with remote by two commits and I cannot push directly. How can I deal with it?
回答1:
DISCLAIMER: git push --force
is dangerous; use it at your own risk.
If you really want to do this and combine commits, you could do it on your local repository using git squash
and then git push --force
in order to overwrite the content on the remote.
--
Note that git push --force
will update the branch to point to your new commits, so the old commits will be inaccessible permanently unless you have the commit identifier or a way to find it and the commit hasn't been garbage-collected. This is generally not possible on hosted git services, though GitHub does have an activity log.
In addition, git push --force
can cause issues if other people are working on the same branch and are not expecting the change.
来源:https://stackoverflow.com/questions/50491446/how-to-combine-commits-and-push-to-the-remote