[ #168 ] Git Squashing Permalink

Git Added less than a year ago and last edited about a fortnight ago

If you decide to choose a development workflow where you are working on lots of branches (perhaps a branch per feature), then you will want to merge branches back to master regularly - like when you've finished your feature. If you have branches for smallish items then you might only want the whole feature to appear under one commit in your master branch - even though your feature branch has many commits.

This is when you should use git's commit squash.

$ git branch
* master
$ git checkout -b feature-01
$ # EDIT A FILE
$ git add .
$ git commit -m "Edit 01"
$ # EDIT ANOTHER FILE
$ git add .
$ git commit -m "Edit 02"
$ git log
 ... output here lists Edit 01, Edit 02 and all previous log messages ...
$ git checkout master
$ git merge --squash feature-01
$ git commit -m "Feature 01"
$ git log
... output here lists Feature 01 and all previous log messages ...

So Edit 01 and Edit 02 now appear in your log the one Feature 01 commit.

If you don't use squash then all the commits from your branch will also individually appear in the commit log for master.

A squash acts like a regular merge in svn.

Colophon

Django Python 960.gs Git Vim NetBSD Nginx

The Author

This is the blog of Brad Willis, a software engineer living in Brisbane.

Meta

Help
Latest entries

*BSD Agile Apache Apple apt Athletics Best-Practice Censorship Comedy Cool Crosswords Deployment Django English Exim Firefox Git Hardcore Health irssi Javascript Jira Languages Linux Makefile Mathematics Mobile Broadband Mutt MySQL NetBSD nginx Nokia OpenVZ OSX Perl Privacy Python Rant Requirements rsync Ruby Shell Slackware SQL SQLite SSH Standards Subversion Television Testing ThisBlog Vim VMWare (Fusion) VPN X zsh

Recent Entries

Checking for exceptions in doctests
Homer's Curling Speech
retry in Python
Vim Makefile tabs
Centos (or RH) IPTables
Converting ssh2 public keys to openssh
Vim comment hints
Context managers in Perl
Dish rotation
Git - fixing commit user
apt stuff
Using shell variables in AWK
Linux - Too many open files
Tell gvim to save and quit... remotely
Vim - automatically remove whitespace at EOL
Python - relative paths from within modules
TV Aspect Ratios
Git - Which commits are in your branch only?
Subversion setup cheat sheet
Force detach a screen session
Modify sudo's use of environment variables
Install all Perl modules
Mutt - delete old messages
OpenVZ VPS and swap space
fail2ban on NetBSD for ssh
NetBSD - Using sup
Python - testing for a sys.exit
Python Best Practice Link Dump
Python script names
Perl - Using an expensive module
Speed of git clone
Perl Modules with Custom Prefix
Perl: tr vs. s
Brilliant sysadmin Reference
Why is GRUB better than LILO?
Why is swap space important?
Perldoc Output
Git's Index
Jira Project Keys
Git GUI

Links

ChoppingBoard, DaveMisc, Project365, RageQuit