0

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?

4

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

A "forced push" will not overwrite anything. Instead, it uploads the new commits to the remote and forces the remote branch to point to the last of those. The previous commits will still be accessible from the reflog, both on the client and the server. The "dangerous" part of a forced push is when you collaborate with others on the same branch and they do not expect such a change.
Okay, maybe my answer is badly written. I'll update it to be better phrased. However, in many cases, including most hosted git sites, the reflog is inaccessible, which makes force pushes permanent.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.