Notes

local-history-cleanup

squash last N commits on current branch (NO rebase)

on branch, clean (committed) workdir

good before a rebase to cleanup and to avoid duplicated work on many commits

# reset HEAD to previous commit, 
# but keep all changes in index and working dir
# to be added and commited 
git reset --soft HEAD~3
#git reset --soft $(git merge-base feature)

git add . 

# add good message and potentially --trailer
# !! new commit !! 
# this also changes the author
# the rebase -i method keeps the original author
git commit

rebase the currently checked out branch

# on current branch, rebase last n commits
git rebase -i HEAD~n

# rebase until common ancestor (a.k.a. the complete feature branch)
git rebase -i $(git merge-base feature main)

rebase current branch to main (latest changes from main into branch)

git rebase -i main
# potentially edit commit message again (add trailer)

git add ?? && git rebase --continue 

merge into main

git switch main
git pull

## ff merge
git merge feature
# or
git rebase feature  # feature points to same tip as HEAD and main

sqash on merge

(rebased) feature, but not squashed

squash on merge (i.e. as maintainer)

# on main (git switch main)
git merge --squash feature  # dangling feature tip

reorder and fixup

example history

nr description
(1) a commit with a "bug"
(2) other commit(s)
(3) "bugfix" commmit for above bug
git log  # find sha of (1)

# the ~includes this commit in the rebase editor
git rebase -i commit-sha~

# move commit (3) under commit (1) and choose "fixup"
# !! 
#    resolving can be tricky 
#    should be isolated to feature and not include other commits in (2)
# !!