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?
- stackoverflow.com/q/5189560/1456253code11– code112018-05-23 14:51:45 +00:00Commented May 23, 2018 at 14:51
- stackoverflow.com/a/8940299/1135424nbari– nbari2018-05-23 14:57:04 +00:00Commented May 23, 2018 at 14:57
- @nbari there is sth different. At the beginning the local and the remote is the same. So when I combine 3 commits locally, the local and remote diverge.david– david2018-05-23 15:13:23 +00:00Commented May 23, 2018 at 15:13
- Possible duplicate of Squash my last X commits together using Gitphd– phd2018-05-23 16:55:21 +00:00Commented May 23, 2018 at 16:55
1 Answer
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.