News for hackers. Stuff that matters.
Re:Y U NO commit?? by akavel on Monday October 20, 2014 @08:11AM (#8481694)
You can really have two "species" of commits:

One of them is the "published, shared" kind; for this one, I can agree with you, that they should be self-contained and complete, especially when there many devs on the project, and/or you'd like to be able to use bisect.

The second kind, and for me actually a very important one, is more of a "local backup, dirty hacking" one. Those shouldn't probably be published (unless a private/one-guy repo), but allow for easy hacking, developing, testing, experimenting. The "commit often, whatever you have, however broken or non-ideal" approach provides safe lightweight backup, and allows for easy switching between various paths/approaches. Now, after you design stabilizes, dust settles down, and you are completing the work, you can (and probably should) eventually either just squash everything into one final feature commit (the end result will be indistinguishable to what you'd deliver if not committing in the meantime), or remodel the intermediary commits to whatever ideal shape you like them to have retroactively (with "git rebase -i", including patch editing etc.) Knowing the benefits of this approach, I don't understand why anyone would want to reject it.

edit: Also, with many small, dirty commits, it's sometimes possible to fairly quickly do stuff like carving out some subfeature into a separate branch (with judicious use of rebases, cherrypicking and some occasional small edits). Or, remove/revert commits marked earlier as DEBUG. Seems useful to me, as a means to somewhat speed up such operations and decrease the possibility of manual error at the same time.

Re:Y U NO commit?? by nhance on Monday October 20, 2014 @09:06AM (#8481891)
This is the workflow we've adopted at my company. There are 2 types of commits, you either want to release some new feature or bit of work and do it atomically, or you want to develop the feature, fix typos and throw it between machines without a care.

Is it ever going to help anyone to `git blame` a line of a file and see a commit message like "Whoops, fixed a typo!"? No. But you can't avoid those types of commits.

What you can do is prevent those commits from going into the released history of the product. We develop all new features in feature branches (made _very_ easy with the commandline tool we built for it) and only after code review and acceptance testing do we squash merge it to master.

This lets us put together all of the commits, typo commits, WIP commits and whatever else into a combined commit that contains all of the changes that make up that feature. We even enforce a special syntax on the commit so when you look back in the history, you can trace it back to the code review and to the actual ticket that requested the work.

This means we keep all of our dirty backup commits until release time when we throw them all away in favor of the squashed commit. It makes git blame on any line of any file a sexy experience that provides accountability and an easy way to figure out why the code is the way it is.

Our commandline tool automates a lot of this for us. It's biggest benefit is the tie in with github (and this week bitbucket) to create pull requests and the "deliver" command that handles squash merging and providing the structure for the final commit.

It's all open source and available here: http://github.com/reenhanced/gitreflow/

Re:Y U NO commit?? by Myrmornis on Monday October 20, 2014 @11:14AM (#8482478)
We prevent force pushes to the remote, so if you need to rebase commits that are on the remote already, you'd have to delete the branch from the remote and re-push, and that closes the PR, which confuses reviewers and causes spurious notifications.

Do you merge master into feature branches between the time the feature branch is first pushed to the remote and when they are reviewed and ready to merge? Can your command line tool handle creating a squashed commit when master has been merged into the feature branch a few times?

Re:Y U NO commit?? by nhance on Tuesday October 21, 2014 @10:37AM (#8487536)
Yes, master is merged into the feature branches before going upstream. We consider it to be the responsibility of the feature branch owner to make sure their code will work with master.

Because we don't care about the commits on the feature branches, we prefer doing a regular merge, not a rebase of the feature branch, so that there's no need for force pushing at any point. We consider a force push of any kind to be unnecessarily dangerous.

The tool will handle the merge up for you, but if there are conflicts you'll have to resolve them before you can release the feature.

Re:Y U NO commit?? by rwong48 on Monday October 20, 2014 @10:55PM (#8485713)
In your flow, how would you update a pull request branch to fix a typo? Make extra commits and normal push?

and how would you update a pull request branch to contain the latest master? Merge back and forth?

From the looks of it, this tool is made for the force-push flow, which doesn't suit you. See https://github.com/reenhanced/gitreflow/issues/52

Re:Y U NO commit?? by nhance on Tuesday October 21, 2014 @10:39AM (#8487547)
Squash merging is only of the feature branch to master. If your feature branch makes it through code review and acceptance and you still need to update the typo, then you make the commit to master directly.

It would be great if we could be perfect, but sometimes small commits to master do have to happen. All we do is make sure we subject every feature to code review and acceptance before it gets to master. If it slips through, then it's technically a new change request in our eyes

Re:Y U NO commit?? by zethraeus on Monday October 20, 2014 @01:35PM (#8483372)
git diff?
Re:Y U NO commit?? by mcherm on Monday October 20, 2014 @08:42AM (#8481785)
Interestingly, I have two different version control systems for doing these two different species of commit. The published kind, I do in my regular team version control system, complete with commit comments that explain the meaning of the complete thought that is being committed. The other kind (bookmarking my state before messing around with things I may want to cleanly revert) I do using the version control that is built into IntelliJ IDEA. It is completely orthogonal to the one used by my team.

Other IDEs should offer this feature... it turns out to be quite useful in practice.

Re:Y U NO commit?? by coob on Monday October 20, 2014 @09:07AM (#8481894)
Re:Y U NO commit?? by visural on Monday October 20, 2014 @08:51AM (#8481828)
Netbeans also has a local history recording feature which is integrated pretty well alongside the git/vcs features (just hit history on any file and see a log of all your local changes intermingled with the committed versions).
Re:Y U NO commit?? by Maken on Monday October 20, 2014 @10:05AM (#8482175)
I think most IDEs nowadays have a local history. The Eclipse one let you compare between revisions like if it were a local git repo, which is useful sometimes.
Re:Y U NO commit?? by Retric on Monday October 20, 2014 @10:05AM (#8482168)
I really like this approach, you can take it one step further. Set up an automatic independent (aka private) commit after every successful compile.
Re:Y U NO commit?? by mcherm on Monday October 20, 2014 @11:18AM (#8482499)
IntelliJ, when you combine the internal version control and the undo log, manages it so that effectively there is a commit after each piece of typing -- without any need to save or even compile. That turns out to be a nice way of working.
Re:Y U NO commit?? by ThrustVectoring on Monday October 20, 2014 @12:33PM (#8483023)
You could easily do this entirely in git. Create a microfeature branch, work in it, and when you've got something you want to commit as a feature, squash and merge onto the feature branch.
Re:Y U NO commit?? by jordigh on Monday October 20, 2014 @08:53AM (#8481839)
> You can really have two "species" of commits:

That's what Mercurial phases are:

http://mercurial.selenic.com/wiki/Phases

Re:Y U NO commit?? by olau on Monday October 20, 2014 @08:53AM (#8481838)
"Knowing the benefits of this approach, I don't understand why anyone would want to reject it."

It's always difficult to have these kinds of conversations in the abstract, but for me it's a slightly cumbersome distraction (unless you don't write commit messages). But if it works for you, you should certainly keep doing it. I tend to divide stuff into small chunks so never work on something for long without something that can be committed.

Re:Y U NO commit?? by akavel on Monday October 20, 2014 @10:51AM (#8482383)
Most usually I still do write commit messages, and that's actually an important additional value of this workflow for me. That said, the commit message is again often a quick and raw: usually a quick in-progress summary of the most important work in the commit, but not perfected at all - just quick something, can have errors, ignores all Commit Message Guidelines like length or whatever. One benefit is, as well noted in other post in the thread, that it will remind me "what the hell was I thinking doing that" when I look at it tomorrow. Second one, obviously, is to help distinguish those commits when doing any sculpting/molding later (i.e. "git rebase -i" & "git cherry-pick" & "git merge --squash").

But that, as I said, is most usually. Sometimes, as you considered, I do write just "WIP" or "dump of current state". The second one, mostly when I already don't remember WTF was I doing here... (i.e. when I forgot to commit month ago and left some stuff on the table). The first one... I'm not sure now. But I know I sometimes do; with some guilt too; but usually the need for having that particular stuff committed is stronger than the guilt...

So, still can't really understand why anyone would want to reject it :) but that said, thanks a lot for expressing your approach. As much as it still puzzles me :)

Re:Y U NO commit?? by vertex-four on Monday October 20, 2014 @08:26AM (#8481726)
Shouldn't we then have a tool which separates out "published, shared" commits from WIP commits, if they're different "types"?
Re:Y U NO commit?? by jordigh on Monday October 20, 2014 @08:53AM (#8481835)
Yeah, Mercurial phases handles this:

http://mercurial.selenic.com/wiki/Phases

Re:Y U NO commit?? by exDM69 on Monday October 20, 2014 @09:12AM (#8481915)
Why would this be advantageous?

If you're using Git or another version control that can do squash/rebase, what would be the advantage of having a separate concept of "temporary commits" or something?

In addition, git has a staging area (git add), which I use to stage intermediate steps of work.

It's a good idea to have only "clean" commits in your master branch (to allow for easy blame/bisect) but you can easily do feature branches that can remain "dirty" before squashing and merging to master.

Re:Y U NO commit?? by lmm on Monday October 20, 2014 @10:24AM (#8482264)
> If you're using Git or another version control that can do squash/rebase, what would be the advantage of having a separate concept of "temporary commits" or something?

It'd be nice to be able to mark commits as "squashable" as I went along (without actually squashing them yet), rather than finishing my feature branch and then have to go back and remember which commits were the "good" ones.

Re:Y U NO commit?? by krupan on Monday October 20, 2014 @10:46AM (#8482357)
As another poster pointed out, Mercurial phases are the answer to this. I don't know if very many mercurial users actually use them this way consciously or not. Most mercurial people that are deliberately and intensely into this workflow learned to use mercurial patch queues before phases existed (patch queues are basically the git staging area on steroids).
Re:Y U NO commit?? by micampe on Monday October 20, 2014 @10:47AM (#8482359)
You can do that with autosquash https://coderwall.com/p/hh-4ea
Re:Y U NO commit?? by lmm on Tuesday October 21, 2014 @08:55AM (#8487036)
Is there an equivalent with a looser match? Half the time I don't remember what my last commit message was.
Re:Y U NO commit?? by micampe on Tuesday October 21, 2014 @01:35PM (#8488525)
No, but this explains a nice trick to use it without remembering the commit message http://technosorcery.net/blog/2012/08/05/updated-git-rebase-...

With that you can do:

    git fixup HEAD~2
Re:Y U NO commit?? by blablabla123 on Monday October 20, 2014 @08:36AM (#8481765)
It's more of a workflow thing. When working on a difficult feature, or rather difficult ticket, that cannot reasonably split into 2, it makes sense to work on a separate feature branch. This branch is just for yourself and can be polluted with dirty commits. Once your done, your can git rebase the thing into one, beautiful commit.
Re:Y U NO commit?? by SargoDarya on Monday October 20, 2014 @08:44AM (#8481794)
If you're working in a feature branch I don't think it would be that much of a problem to be honest. Just be sure to squash the commits before writing the pull request later on.
Re:Y U NO commit?? by megablast on Monday October 20, 2014 @09:00AM (#8481870)
What do you mean by squashing the commits? Why would it matter if you do a pull request after committing a lot?
Re:Y U NO commit?? by ulisesrmzroche on Monday October 20, 2014 @10:50AM (#8482374)
You can squash or rebase history in Git, which basically means you compress all your changes into a single one. People use this to keep a clean history.
Re:Y U NO commit?? by jules on Monday October 20, 2014 @10:25AM (#8482270)
I would like to commit on every keystroke + a mechanism to hierarchically group commits.
Re:Y U NO commit?? by novaleaf on Monday October 20, 2014 @12:04PM (#8482810)
this is what I use a "$YOURNAME$-dev" branch for. all my hacks / etc go there and only "proper" work gets merged upstream.