6 ms·
Or just clean up your local history before you push. Frequent commits are handy for checkpointing a known state so you can experiment freely and easily revert f
by throwanem 10y ago
Or just clean up your local history before you push. Frequent commits are handy for checkpointing a known state so you can experiment freely and easily revert failed attempts; then, when you know you've got something good, you can squash the relevant commits and rewrite the messages to provide solid detail, and push a clean result.
Interactive rebase is an amazingly powerful tool - a little hard to use at first, but the investment of effort to learn its capabilities pays off manyfold. If you're looking for an easy way to level up, and you haven't investigated it before, I can't think of a better choice.
- _asummers 10y agoTooling makes interactive rebasing a bit easier. Magit in Emacs makes it simple and it's just part of my normal flow now. The other thing you can do is do git add -p. In CLI, that menu sucks, but in emacs you can simply stage and unstage hunks or even individual lines from the diff with a few keys. Using those has made committing small chunks much smoother of an experience for me.
- adrianN 10y agoThe built-in git GUI also makes that very easy.
- _asummers 10y agoHaving it in my editor is an important property for me, but that's good to hear! Getting more people comfortable with that is good for git and histories everywhere.
- Myrmornis 10y agoWhat magit offers over the CLI, in the area of reworking commits, is actually rather spectacular. It's more than interactive rebase -- it's e.g. the ability to selectively stage individual lines (or hunks or files) and chooose which commit to apply them to as a fix up. It's definitely worth trying as a non-emacs user; if you're interested I can post instructions for starting a one-off emacs instance for magit and nothing else.
- _asummers 10y agoPlus the ergonomics and mnemonics of the keys is really nice. You bring up a menu with a keypress, and then the most common command in that menu is typically just a second press of that key. E.g. c brings up commit menu and pressing c again to bring up the commit message writer, or c a for commit amend, etc. For branches, b b switches branches, l l for logs, r r for rebase continue, p p for push upstream, things like that. Then at any commit sha or file, you can move your point to it and hit enter to view that thing. Or just hit tab to see the diff. It's quite nice.
- andreimackenzie 10y agoCompletely agree. One of git's strengths is the flexibility to support many development styles and workflows. It's possible for each developer to follow their own style locally, but still have a consistent team style once commits land on 'master' following rebase. Learning about interactive rebase greatly aided by local development flow, because it freed me from too much agonizing about commit structure before much code is written. It's a lot easier to decide how to structure commits to tell a story with the code in front of you.
- Terr_ 10y agoI think it helps to think of git as a toolkit for designing a workflow, rather than a final product itself.
- hdhzy 10y agoIIRC that's almost exactly what Linus said about git: that it's rather a toolbox for creating SCM rather than SCM itself [0]. [0]: http://www.youtube.com/watch?v=4XpnKHJAok8 http://www.youtube.com/watch?v=4XpnKHJAok8
- golergka 10y agoPlease don't do that. Development history like frequent commits and merges has enormous value, for bisecting and debugging. Once detroyed, it's never coming back. What's the purpose of git commit tree at all if it doesn't truthfully represent the development process?
- chrisweekly 10y agoWhy not preserve full commit history in feature branches, iterate with code reviews on pull requests, then squash when merging to an integration branch? This way master is clean and comprehensible, and there's an accurate, complete commit history available if needed.
- Androider 10y agoThat is exactly what I do, even if working on a project by myself. My feature development branch will have a commit for each logical change, typically 3-5/day done by staging individual chunks with "git add -p" (exclusively) as a "I'm done with this piece" checkpoint, still leaving all debug and still in-progress parts in my working copy only. But I wouldn't hesitate to do a "I'm moving from my laptop to my desktop" work-in-progress commit either. Later commits will frequently undo changes done in earlier feature commits, or just revert a commit outright if it proved to go down the wrong development path. You really can't commit too often in my opinion, and it's incredibly freeing knowing you can make sweeping changes and then back out of them at a moments notice. For merging, I will rebase on master, squash everything into 1 or a few logical commits, and _review_ the resulting commit diff manually as if I were to send it to a maintainer. I will write an extensive commit message based on the code review as a kindness to my future self. The development branch still exists and can be referred to at any time, but I don't want to see that cruft when looking at the project log.
- wschroed 10y agoRebase is not destructive. It creates new patches based on the previous. This confusion is caused because a rebased branch tag is given a new home; however, you can always add another branch tag to the original HEAD so you can revisit it easily, and you can always find the original HEAD via the reflog. If the branch is not tagged, the default git policy is about a month before garbage collecting the untagged end. Pre-push commit history is purely for the developer. A push is a publish, which means you are now presenting work for others to view and understand, code review, maintain, and use to debug. There is no more value to people to see every commit for a typo-fix, rollback, and redirection than there would be if our text files kept a complete and honest history of your every backspace. Nobody else wants to watch the rambling movie. BUT that movie can be important to you for a time, and can remain on your local git repo. If the commit history is getting long in the tooth, it does help to clean it up fairly often, and I have found that cleanup for long-running branches to be much more valuable to my memory than trying to walk or bisect through every minute of my development process. A quick note about merges: A merge should have something more interesting than "developer merged branch foo onto master"; a merge introduces something important, and old branch names may not exist in the future at all or on the same commits. If one follows this rule of thumb -- make commit messages useful -- then the fact that you were updating your branch with the latest master becomes unimportant. It is actually noise and confusion for anyone having to dig through commit histories, due to the massive number of forks. In other words, always rebase onto master first before merging. I look at commit history as a document that I can polish and present to others. I look at my code the same way, trying to make it readable for other humans. This is writing prose. I group like things together. Each commit is a solid microfeature. There are no typo commits.