Skip to content

Commit

Permalink
chapterwide: rename linking commit placeholders to CHAPTER_$CURRENT_F…
Browse files Browse the repository at this point in the history
…OLLOW

This is done in order to avoid having to change the Markdown files to
stay consistent when chapters are reordered
  • Loading branch information
miallo committed Jan 15, 2024
1 parent 6cce26f commit a05ad21
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
18 changes: 8 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ commit -m "WIP: add description on branches
nuggit: ShowMeMore"
# For reference in commit.md later
BRANCH_COMMIT="$(git rev-parse --short @)"
CHAPTER_COMMIT_FOLLOW="$(git rev-parse --short @)"

# ------------------------------------------------------------------------------------------- #
create_chapter working with branches
Expand All @@ -103,10 +103,10 @@ commit -m "WIP branch: add explanation on how to list local branches"
# ------------------------------------------------------------------------------------------- #
create_chapter commit
git switch --detach main
replace BRANCH_COMMIT "$DOCDIR/03_commit/commit.md" > commit.md
replace CHAPTER_COMMIT_FOLLOW "$DOCDIR/03_commit/commit.md" > commit.md
git add commit.md
commit -m "Add description on commit"
CHAPTER_COMMIT_COMMIT="$(git rev-parse --short @)"
CHAPTER_DIFF_FOLLOW="$(git rev-parse --short @)"

# ------------------------------------------------------------------------------------------- #
create_chapter cherry-pick
Expand All @@ -115,7 +115,7 @@ CHAPTER_CHERRY_PICK_FOLLOW="$END_COMMIT"
replace CHAPTER_CHERRY_PICK_FOLLOW "$DOCDIR/10_cherry_pick/cherry-pick.md" > cherry-pick.md
git add cherry-pick.md
commit -m "Describe cherry-pick"
CHAPTER_CHERRY_PICK_COMMIT="$(git rev-parse --short @)"
CHAPTER_INTERACTIVE_REBASE_FOLLOW="$(git rev-parse --short @)"

# ------------------------------------------------------------------------------------------- #
create_chapter interactive rebase
Expand All @@ -130,19 +130,17 @@ git add interactive-rebase.md
commit -m "WIP: finish sentence on interactive rebases"
INTERACTIVE_REBASE_EXAMPLE_PICKS="$(git log --oneline main..@ | sed 's/^/pick /' | sed 's/$/\\/g')
[...]"
# FIXME
CHAPTER_AMEND_COMMIT="$CHAPTER_CHERRY_PICK_COMMIT"
replace CHAPTER_AMEND_COMMIT INTERACTIVE_REBASE_EXAMPLE_PICKS "$DOCDIR/07_rebase_merge/interactive-rebase-continued.md" >> interactive-rebase.md
replace CHAPTER_INTERACTIVE_REBASE_FOLLOW INTERACTIVE_REBASE_EXAMPLE_PICKS "$DOCDIR/07_rebase_merge/interactive-rebase-continued.md" >> interactive-rebase.md
git add interactive-rebase.md
commit -m "Finish describing interactive rebases
TODO: squash commits..."
INTERACTIVE_REBASE_COMMIT="$(git rev-parse --short @)"
CHAPTER_REBASE_FOLLOW="$(git rev-parse --short @)"

# ------------------------------------------------------------------------------------------- #
create_chapter rebase/merge
git switch --detach main
replace INTERACTIVE_REBASE_COMMIT "$DOCDIR/07_rebase_merge/combine_history.md" > combine_history.md
replace CHAPTER_REBASE_FOLLOW "$DOCDIR/07_rebase_merge/combine_history.md" > combine_history.md
git add combine_history.md
commit -m "Add description on how to combine branches"

Expand Down Expand Up @@ -193,7 +191,7 @@ STAGING_DIFF_DESCRIPTION='For seeing what would be committed next you can run `g
STAGING_NUGGIT='nuggit: CommitmentIssues'
COMMIT_DESCRIPTION='To see the difference between your current working-directory (the files you see in the folder) and a commit, you can add a hash, and also if you want a path (add "--" before the path to tell git that the remaining arguments are paths:
```sh
git diff '"$CHAPTER_COMMIT_COMMIT"' -- commit.md
git diff '"$CHAPTER_DIFF_FOLLOW"' -- commit.md
```'
{
echo "$UNSTAGED_NUGGIT"
Expand Down
2 changes: 1 addition & 1 deletion src/03_commit/commit.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ A commit can be addressed by a "hash". That is a seemingly random string of numb

To view the commit message and diff for a commit there exists the command `git show`. By default it will show the last commit, but you can also show a specific one like this:
```sh
git show BRANCH_COMMIT
git show CHAPTER_COMMIT_FOLLOW
```
4 changes: 2 additions & 2 deletions src/07_rebase_merge/combine_history.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Since a commit consists not only of the diff, but is a complete snapshot of the

So to sum it up: with the rebase-workflow the end result will look like you had the changes from the main branch all along while working on the feature, which makes it a lot easier to understand what changed when and why, because you don't have to mentally keep track of all commits in the branches that were eventually merged at the same time, but can step through the history one by one. This comes at the cost of having to retroactively "rewrite the history".

Suppose you want to get all the changes from the commit INTERACTIVE_REBASE_COMMIT, then you would run:
Suppose you want to get all the changes from the commit CHAPTER_REBASE_FOLLOW, then you would run:
```sh
git rebase INTERACTIVE_REBASE_COMMIT
git rebase CHAPTER_REBASE_FOLLOW
```

Another benefit of rebases is that the history of the branches can be cleaned up retroactively (e.g. when you want to safe snapshots of the code while developing, even though it is not completely functional yet, or it works, but after you implemented it you have ideas on how to refactor it).
Expand Down
2 changes: 1 addition & 1 deletion src/07_rebase_merge/interactive-rebase-continued.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
When you run
```sh
git rebase -i CHAPTER_AMEND_COMMIT
git rebase -i CHAPTER_INTERACTIVE_REBASE_FOLLOW
```
(or `--interactive`), an editor will open, showing a list of all the commits that would be applied.

Expand Down

0 comments on commit a05ad21

Please sign in to comment.