Live data from Hacker News

Git add -p: a powerful git feature

johnkary.net

31–40 of 108 posts

Re: Git add -p: a powerful git feature

#31
post #21

So you end up committing untested code? (since you did test the whole change, not just part of it). Sounds like a bad idea to me.

None of this implies committing untested code. The index is not a commit; it is a pre-commit staging area. When you use 'git add -p', you are adding hunks to the staging area, not committing them.

What's the difference? When you're done staging your patch, you can then check out the staging area and run unit tests on it prior to promoting it to a commit. Doesn't compile? Tests fail? Restage as necessary.

Re: Git add -p: a powerful git feature

#32
post #21

So you end up committing untested code? (since you did test the whole change, not just part of it). Sounds like a bad idea to me.

I usually do something like:

  git add -p
  git commit
  git stash
  
If it fails then I can stash pop and commit -p --amend and try again.

Re: Git add -p: a powerful git feature

#33

Link is down. Cached page at: http://webcache.googleusercontent.com/search?q=cache:ybdWn7-...

Every time I mention this on HN, at least 15 people upvote it - which means they didn't know about it. So I feel obliged to repeat it again and again (as I usually use this method a few times a week and it's tremendously useful for me):

If you want to get Google's cached version of a webpage, just type

    cache:[url]
    e.g.: cache:http://johnkary.net/git-add-p-the-most-powerful-git-feature-youre-not-using-yet/
in the search bar and press return.

EDIT: 14 already, after an hour!

Re: Git add -p: a powerful git feature

#34

John Kary's page is down, but he created two screencasts, which are the meat of his post: http://www.youtube.com/watch?v=Wl0NfWYrvlY&feature=plcp http://www.youtube.com/watch?v=1tqMjJeyKpw&feature=plcp

Sorry everyone, thought we had Varnish setup. I'll do my best to get it back up. My screencasts above are what I'm mostly linking to.

Re: Git add -p: a powerful git feature

#35
post #21

So you end up committing untested code? (since you did test the whole change, not just part of it). Sounds like a bad idea to me.

I usually do something like: git add -p git commit git stash If it fails then I can stash pop and commit -p --amend and try again.

With stash -k you can test without committing first. Although git is very flexible regarding this, I prefer to at least test the code before committing it.

Re: Git add -p: a powerful git feature

#36

OT: I'd love an interactive "Learn Git" webpage where you could learn to use Git with demo scenarios. Something like "Try Ruby" but for git.

You didn't look very hard then :] There is a course made by the same people who made Try Ruby, on the same site. It's named, unsurprisingly, 'Try Git': http://www.codeschool.com/courses/try-git They also have a second, more advanced course on the site.

:( Wow. I failed pretty hard at looking clearly. Thanks to you and the others for the links.

Re: Git add -p: a powerful git feature

#37

John Kary's page is down, but he created two screencasts, which are the meat of his post: http://www.youtube.com/watch?v=Wl0NfWYrvlY&feature=plcp http://www.youtube.com/watch?v=1tqMjJeyKpw&feature=plcp

Sorry everyone, thought we had Varnish setup. I'll do my best to get it back up. My screencasts above are what I'm mostly linking to.

There's a cache of the article here: http://hncache.bensbit.co.uk/4744405?textonly=1

Re: Git add -p: a powerful git feature

#38

Earlier quoted context omitted.

That is most definitely a major issue of this technique, though it can probably be mitigated through various hooks.

I find this technique great to keep unrelated fixes in separate commits. A single revision may not pass a set of unit tests, but the entire feature branch will before being merged into the release line. Keeping the barrier low for committed code is one of git's best features.

> Keeping the barrier low for committed code is one of git's best features.

When I first learned git, I was told, 'You'll never have to comment out code again'. Keeping the barrier for commits low (along with git -p and git rebase -i) makes this a reality.

Re: Git add -p: a powerful git feature

#39
post #20

OT: I'd love an interactive "Learn Git" webpage where you could learn to use Git with demo scenarios. Something like "Try Ruby" but for git.

All you need to do is type "apt-get install git-core" or "brew install git" and you can try 95% of git out locally. Get a free bitbucket or github account and you can do most of the rest. :) OK, perhaps you are on Windows, then i am not sure if it's that simple.

Step 2: write some code that exercises all git features

Re: Git add -p: a powerful git feature

#40
post #21

So you end up committing untested code? (since you did test the whole change, not just part of it). Sounds like a bad idea to me.

I usually do something like: git add -p git commit git stash If it fails then I can stash pop and commit -p --amend and try again.

`git checkout-index` allows you to run tests on the index before committing and without messing with your working tree. The only downside is that it might take a while for a large project. Example script: https://github.com/philc/vimium/blob/master/git_hooks/pre-co...
Post reply on HN