I make a commit that introduces a bug and contains a typo. Someone else points out the bug, so I fix the bug. Then someone else points out the typo so I fix the typo, one small commit for each fix. While this is indeed an accurate depiction of history, having three commits (one broken, and two silly short one character/line changes) in your commit history instead of one commit is not in any way useful here. For anyone reviewing a pull request or doing anything else that involved looking through the history (that's what history is for, right?), this is a waste of time, and unnecessarily sloppy. Or if you need to cherry-pick or bisect, for example, you now have three commits that represent one change, rather than one commit for one change.
Let's say someone makes a pull request to one of my projects for a change they made that ends up having 5 commits fixing things they did wrong initially, that could be 1 or 2 commits. There is zero chance I'm going to say "Ah well, I guess that's an accurate representation of history! Let's merge it!" I'm going to tell them to squash and rebase their commits to clean it up, then force push. And to be honest, I think anyone who didn't do this would be doing it wrong, promoting a messy history in their project.
Generally, this whole debate within git is referred to as whether you should "hide the sausage" or not. Further discussion can be found here, with lots of arguments I didn't touch on at all in this comment: http://sethrobertson.github.io/GitBestPractices/#sausage
Anyhow, generically, while your changes are local, rewrite history to your hearts content. Have it tell a development story that makes sense. The real important part is: you can rewrite history only while it is private. When you push the commits, never ever rewrite history.
Namely, rebasing is not a replacement for merging.
If you want to have a perfect public repo history, you can revert your change, fix it in private, then push the modified version to the public repo.
* How many times have you read a project history commit by commit? How much time the occasional typo-commit took you to read? The probalbe answer, if measure would be negligible. Yet you're ready to spend time rewiting history. Which can cause real and known time wate as people have to rebase remerge, and sometimes cause all the problem that have been outlined.
* The whole point of bisect is using a logarithmic search into history. The rare typo-fix commit won't affect its runtime. Again, this is wasting time for no measurable effect.
* Stop the micro-fixing commit already in the first place!
But what really annoys me is that all these are the symptoms of a deeper disease: mis-managed repos. This first thing to do if you have the legendary 50GB log show up in your repo is not to rewrite history. The first thing to do is to make an urgent note to review your repo management processes. How did that file get in there in the first place? Are you pulling directly in your main repo!? The correct practice is to always pull into a staging repo and only merge into main if clean. How do you know it's clean? Easy: use the double-staging repo trick: pull into a staging repo make sure everything is shape (human manual process) then pull into another clean-from-main staging repo and diff the history. If the diff is not empty, you know something is wrong. Only when diff are clean do you pull from that staging repo into main.
(BTW, that double staging is only necessary if you allow yourself to do cleanup in the staging repos. If you always insist on clean pull, then all the cleaning up is done elsewhere. This is not always possible / easy /efficient to do on busy repo. And on your private working repo, do as you please, as long as the pull then comes off clean.)
(Also, I recommend doing the same on your private working repo. I always find it easier to have clean copy of the main repo, one staging repo where my own cersion of clean-up history is kept and the real dirty-work repo yet a third repo. The fact that I prefer to work with mercurial which works best by cloning rather than branching pretty much enforce this discipline. It promotes happy collaborations since you never pull into your work repo and you never push from it.)
Because we, the rebasers, don't consider the repository to be "history".
If you stop thinking of it as history, your whole perspective changes.
It may fool you into thinking that it's history because there are dates everywhere, but it's really just a big collection of ordered changesets.
With that in mind:
> - accidental reintroduction of commits rebased upstream are the result of wrongly rewriting history upstream. You can't rewrite history when history is replicated along several repos.
Of course you can. Your local repo and the remote servers you have access to are malleable and can manipulated however you'd like. I happily force push when the situation calls for it.
However, it does place a burden on everyone else who fetches/pulls from that repo and so one need to take that into consideration. For major screwups (like the 50gb file accidental checkin from the article), it's very, very good that this can happen.
For one of my projects I'm using git-multimail[1] on our "master" repo and it handles force pushes brilliantly (sends out emails with a list of commits removed/added). This is a great way to communicate with the rest of the team when you have a rewrite-after-push culture.
„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. This section explains how to do the fix from the downstream’s point of view. The real fix, however, would be to avoid rebasing the upstream in the first place.“--https://www.kernel.org/pub/software/scm/git/docs/git-rebase....
me too... i really enjoy history being immutable and accurate. all of the arguments i've heard for pruning history tend to boil down to ease of use - but i strongly suspect its a spurious argument, and that the perceived ease of use stems from not even having considered the alternatives and following the crowd (which is afaik why most people using git are using it broadly)
Your teammates don't care much if you do the former. From their perspective, it's the same as if you'd committed at different points in your development process. So long as your final, rewritten history doesn't violate your team's preferences as to the granularity of commits, you're fine.
So go ahead and rewrite your local, un-pushed changes if you feel it makes the history more organized.
But if you do the latter--rewriting history that has been pushed--you're in trouble. All developers should be able to assume that the history in the central repo is immutable. Most likely, they will rely on that assumption.
You can even rewrite a branch shared between developers that hasn't been merged mainline: once it's done, have one of the developers create a duplicate branch in their own private namespace, and rebase and merge that.
Accidents happen, though. If you want to be guaranteed safety, enforce that every developer have their own remote fork. They can rebase at-will on their own fork, and submit pull requests to the mainline repository. (If you're using GitHub, this is dead simple, since you can open pull requests across forks.) This method introduces a fair bit of hassle and overhead for a smallish team, though.
Alternatively, if you use github, you can set access controls on forks to read-only and send pull requests from your fork to the main repo.
Amen.
Since pull merges others' commits on top of yours, the diff it creates is full of their changes but has your name on it, which clouds blame and history and makes conflict resolution more difficult. I think this is something git should fix.
See this article about merge direction: http://tech.novapost.fr/merging-the-right-way-en.html
Git is a highly useful tool but it's also an incredibly flawed one, especially in that most critical aspect for all software: the merger of technical and human concerns.
Git is a useful set of source control primitives but it's lacking the cohesion necessary to make it a truly great tool. The fact that it's so popular is largely a consequence of the state of competition rather than its own internal awesomeness. One consequence of this is that instead of a robust, well thought out set of use cases which mesh well with various real-world applications git instead has a few hacky workarounds for certain scenarios. This results in the inevitable wobbliness of any system built on top of hacks and leaky abstractions. Rebasing being perhaps the ultimate example of just that.
Personally I think history should largely be treated as immutable (it's funny how in programming we've become more and more attuned to the values of immutability while in source control we've become more amenable to mutability) but with some sort of system designed to make viewing history easier for the user (lots of other source control products have precisely this, it's sort of silly that git doesn't).
- nonlinearities aren't intrinsically bad. If they represent the actual history they are ok.
- accidental reintroduction of commits rebased upstream are the result of wrongly rewriting history upstream. You can't rewrite history when history is replicated along several repos.
- modifying the working directory is an expected result; of debatable usefulness, namely in the face of the behaviour of hg/monotone/darcs/other_dvcs_predating_git, but again not intrinsically bad.
- pausing to review others' work is needed for a merge, again an expected behaviour on git pull
- making it hard to rebase against a remote branch is good. Don't rewrite history unless you absolutely need to. I can't for the life of me understand this pursuit of a (fake) linear history
- Not cleaning up branches is good. Each repo knows what it wants to hold. Git has no notion of master-slave relationships.