Chapter 20. Tips, Tricks, and Techniques
With a plethora of commands and options, Git provides a rich resource for performing varied and powerful changes to a repository. Sometimes, though, the actual means for accomplishing some particular task are a bit elusive. Sometimes, the purpose of a particular command and option isn’t really clear or becomes lost in a technical description.
This chapter provides a collection of various tips, tricks, and techniques that highlight Git’s ability to do interesting transformations.
Interactive Rebase with a Dirty Working Directory
Frequently, when developing a multicommit change sequence on a local branch, I realize that I need to make an additional modification to some commit I’ve already made earlier in the sequence. Rather than scribbling a note about it on the side and coming back to it later, I will immediately edit and introduce that change directly into a new commit with a reminder note in the commit log entry that it should be squashed into a previous commit.
When I eventually get around to cleaning up my commit sequence, and want to use git rebase -i, I am often midstride and find myself with a dirty working directory. In this case, Git will refuse to do the rebase.
$git show-branch --more=10[master] Tinker bar [master^] Squash into 'More foo and bar' [master~2] Modify bar [master~3] More foo and bar [master~4] Initial foo and bar. $git rebase -i master~4Cannot rebase: You have unstaged changes. Please commit or stash them.
As suggested, ...