I alias icommit="!git add -p && git commit -e -v" since i normally do the two together.
Git add -p: a powerful git feature
51–60 of 108 posts
Re: Git add -p: a powerful git feature
#52I can't remember the last time I used a naked commit; record has become part of my core workflow.
Re: Git add -p: a powerful git feature
#53So 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.
Re: Git add -p: a powerful git feature
#54It's an absolutely fantastic (though dangerous) command. It's also a good illustration of how git doesn't commit anything you don't want to see committed (eg, "git commit" doesn't do anything if you haven't done "git add" before, letting you prepare your commits more carefully than with other VCSs).
You really need to test the version of the code you are going to commit. See the comment about using "git stash" elsewhere in this thread.
I use git add -p whenever I've made too many changes between commits. I like for my commits to be of a single topic if possible.
If I use git add -p to break up a commit into 10 separate chunks, and find out something is broken, it's not hard to find the commit that caused the issue (if the commits are topical and not mixed).
Re: Git add -p: a powerful git feature
#55Re: Git add -p: a powerful git feature
#56Re: Git add -p: a powerful git feature
#57I tend to use it even for git just so I have a consistent interface no matter what project I'm working on.
Re: Git add -p: a powerful git feature
#58The best thing is the discoverability - you don't need to know about the -p flag, for instance, since it's handled by the UI. Same for many other useful git commands that are hard to remember - they are often a simple option on a right-click menu, or a checkbox when performing an operation.
Re: Git add -p: a powerful git feature
#59In Mercurial, I would use an hg patch queue to hg qpop, qrefresh, then qpush.
Re: Git add -p: a powerful git feature
#60When preparing a series of commits in a branch, what is the recommended method for editing non-HEAD commits? I know how to git commit --amend the HEAD commit, but how would one modify an earlier commit and rebase/replay the subsequent commits? git checkout the earlier commit and create a new branch from there? In Mercurial, I would use an hg patch queue to hg qpop , qrefresh , then qpush .