dougvk
dougvk

Reputation: 3734

How do I rebase git history after several pushes, then push the updated history?

Often I work with heroku, and near the end of a project I have several small commits to fix some unexpected bugs. This results in 10 small diff commits that I wish to rebase into one. Problem is, the history has already been pushed. How do I reconcile these things?

Upvotes: 3

Views: 1811

Answers (4)

Norman Richards
Norman Richards

Reputation: 1626

What you want to do is nowhere near as bad as what people suggest. It's true that you don't want to rebase changes pushed to a shared master branch, rebasing changes sent to a non-shared/working branch or to a non-shared repository is very common. Many people consider it a BETTER practice than cluttering the project history with meaningless (and possibly incomplete/nonworking commits).

The question to ask yourself is "will anyone be pulling from the branch I am pushing to". If the answer is no, then the problems with doing so are only theoretical and far outweigh the problems of a cluttered history. If the answer is yes, then of course you don't want to do that. However, in that case you should ask yourself whether or not you can deploy from a non-shared branch in that repository. Create a work-in-progress test branch, commit and rebase freely. When you are done with your work, rebase to your hearts content and push that good commit to the shared branch.

Upvotes: 6

dhwthompson
dhwthompson

Reputation: 2509

If you really want to push a rebased branch (which Git will reject by default), you can use the following command:

git push --force heroku master

Just be aware that this is, in general, a really bad idea, for the reasons others have already mentioned.

Upvotes: 5

Mariusz Sakowski
Mariusz Sakowski

Reputation: 3280

From git-rebase man-page: Rebasing (or any other form of rewriting) a branch that others have based work on is a bad idea; anyone downstream of it is forced to manually fix their history.

So generally - don't rebase after you pushed anything.

Upvotes: 0

tjarratt
tjarratt

Reputation: 1690

You shouldn't rewrite history (rebase) after you've already pushed. If someone else pulls from that remote, and you rebase and push, you'll have terrible terrible merge conflicts.

Upvotes: 2

Related Questions