Hacker News new | past | comments | ask | show | jobs | submit login

I would also add "commit often, squash later". I find frequent local commits useful for quickly rolling back mistakes but they'd just clutter the main history if they got there. Usually if a commit is important enough to end up in master, it is also important enough to do the merge so most of my changes are actually 1 commit (2 if you count the --no-ff merge.)



Learning git here. Could you please explain how rebase squashes commit ? Looking at man git-rebase it seam that it detaches a branch and attaches it to the current branch. From the documentation the chain of commits is preserved and simply moved in the graph. The sequence of commit nodes of the branch are not merged into one commit node.


If you use rebase interactive like this:

   git rebase -i HEAD~n 
Where n is number of commits from HEAD, you can do ANYTHING to your branch. You can stop mid rebase to add some files that didn't exist before, squash, fix, execute commands, etc.

You can even change order of commits and delete commits from history. BE VERY, VERY CAREFUL!

https://www.kernel.org/pub/software/scm/git/docs/git-rebase.... (See interactive mode and splitting commits).


In addition to the other responses (i.e. 'rebase -i'), there's also the shortcut of passing the '--squash' option to the final 'merge' command. This, unlike the standard 'merge' does not create a commit but instead applies all the commits from the merged branch into your working tree. You can then review the changes and create the commit yourself.


If you work on a feature branch originating from master, what you do is "git rebase -i master" to squash your commits.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: