I’m writing a technical book. It has an example project that I build up throughout the book. Using git in the regular way is no problem of course.
But when a new version of the software comes out: that could mean a small change somewhere right in the beginning of the code… A small change in the initial generated code. How do I make that change in, say, the second changeset and have it propagate throughout the examples?
Or I might decide to change a variable name in chapter two. That has to propagate in all the following chapters’ examples.
There’s probably a git trick I can use to pull this off, so I’m all ears for a useful tip.
It sounds like you’re arranging the Git repository so that a “commit” corresponds to a “chapter” (or something similar). Assume that each revision is tagged with a tag name
chapter-xfor the following:First, go back to the chapter you want to change:
Make the change to the code, and commit it, amending the original
chapter-2commit:Update the
chapter-2tag to point to the new, amended commit:Switch back to the end of your book:
and finally, rebase against the new
chapter-2:This will rewrite chapters 3 and beyond so that they are based off the change you made in chapter 2. Note that you may encounter a lot of conflicts doing this (especially if, in later chapters, you modify code involving whatever you changed in chapter 2). Git can help, but unfortunately it can’t do all the work for you.