tags:

views:

177

answers:

3

I'm wondering, how could I avoid a commit in really small changes of code. For instance, sometimes I miss a space between parameters or that kind of tiny code formatting. The reason I ask this is because later I have to push my commits to a remote repository and I don't want to include those small changes.

Any ideas? Thanks

+14  A: 

The only way to make a change is with a commit. However, you could amend a previous commit to include the new change if you like. This may be the best solution when you haven't pushed the previous commit to a remote repository yet.

There's good information about amending git commits in the Git user's manual and in a blog post.

David Underhill
Thanks for the links. However, I don't like [clickhere] linking style. Here is an useful bookmarklet for generating descriptive links: [Copy the markdown link or edit it](http://pastebin.com/qEafAErg) (pastebin link)
takeshin
+11  A: 

I'd recommend checking out the rebase command for this. It does exactly what you are asking for

What this does is take smaller commits and combine them into larger ones

To use it:

git rebase -i HEAD~5

Your editor will pop up with the last 5 commits from the head of the current branch, with some documentation. In your case you will want to use squash. The site I linked explains it really well, they have this example:

pick 01d1124 Adding license
squash 6340aaa Moving license into its own file
squash ebfd367 Jekyll has become self-aware.
squash 30e0ccb Changed the tagline in the binary, too.

This will package the previous 3 commits and put them all under the one you've marked as pick. You can then modify the commit message and so forth.

Have fun

Bartek
Why the downvote?
meagar
+1. Squashing is the way to go. More information here: http://www.gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
Jeet
+1  A: 

One of the best ways to address this is to use git difftool to run a visual tool like xdiff or winmerge on every modified file before committing. This makes it easy to undo minor changes and will catch significant changes you forgot you made and aren't ready. I catch a fair number of bugs this way. For example, a missing or extra html tag can be hard to spot when you are looking at code, but is easy to spot when you do a diff.

mikerobi
Is there some reason you wouldn't just use `git diff`? That's one of its primary purposes...
Jefromi
@Jefromi, git diff doesn't let me edit code and revert portions of files. Also, I find it much more help full to have a side by side diff of the full file contents helps me catch mistakes I might miss with a line by line diff (I wouldn't be surprised if there is an option for this, but it wouldn't make up for the lack of editing)
mikerobi
Have you tried git difftool?
bstpierre
@bstpierre, that was implied, edited the post to be clear.
mikerobi
@mikerobi: Ah. I thought this was mostly in a verification context, where you wouldn't be likely to edit, just add/reset changes from the index. Cool.
Jefromi