Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I avoid committing small changes in git?

Tags:

git

commit

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

like image 345
Robert Avatar asked Jul 12 '10 23:07

Robert


2 Answers

Update: As others pointed out, do not do any rebasing, or history re-writing of any sorts if you've pushed to a remote origin and shared this code with other developers. Short answer: It's dangerous and risky!

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

like image 177
Bartek Avatar answered Oct 01 '22 20:10

Bartek


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.

like image 23
David Underhill Avatar answered Oct 01 '22 21:10

David Underhill