HACKER Q&A
📣 pm2222

How to Do This in Git


Suppose I'm writing a tutorial and as a simple example there's only one source file. Incremental changes will be made to this file step by step along the way. So far I this have commit history: commit1-commit2-commit3-...-commit100-(Head)

commit1:

  This is step1
commit2:

  This is step1
  This is step3
commit3:

  This is step1
  This is step3
  This is step3
..

Commit100:

I wish to be able to tell readers to go to commitX for source file of stepX.

Now obviously in commit2 there's a typo and it's inherited by commit3 and so on. What's the best way to achieve my goal, is it a natural thing for git to do?


  👤 cratermoon Accepted Answer ✓
Branch at commit1, make a new commit2, commit2a, then rebase commit3 onto commit2a

👤 fargle
interactive rebase can do this:

    git rebase -i commit1
it will open an editor. find commit2 in the text file and change "pick" to "edit". save&exit editor

it will dump you out on commit2 (with the typo). use an editor to fix the typo in typofile. then:

    git add typofile
    git commit --amend
    git rebase --continue
then it will rebase the other 99 commits on top, if there are any conflicts it will stop and you'll have to fix them.

you can optionally skip the git commit --amend right after git add and rebase --continue does it automatically anyway.