I just squashed some commits with git rebase and did a git push --force (which is evil, I know).
Now the other software engineers have a different history and when they do a git pull, Git will merge. Is there a way to fix this, except doing a rm my-repo; git clone git@example.org:my-repo.git?
I need something like the opposite of git push --force, but git pull --force did not give the intended results.
To receive the new commits
Reset
You can reset the commit for a local branch using
git reset.To change the commit of a local branch:
Be careful though, as the documentation puts it:
If you want to actually keep whatever changes you’ve got locally – do a
--softreset instead. Which will update the commit history for the branch, but not change any files in the working directory (and you can then commit them).Rebase
You can replay your local commits on top of any other commit/branch using
git rebase:This will invoke rebase in interactive mode where you can choose how to apply each individual commit that isn’t in the history you are rebasing on top of.
If the commits you removed (with
git push -f) have already been pulled into the local history, they will be listed as commits that will be reapplied – they would need to be deleted as part of the rebase or they will simply be re-included into the history for the branch – and reappear in the remote history on the next push.Use the help
git command --helpfor more details and examples on any of the above (or other) commands.