Skip to content

Instantly share code, notes, and snippets.

@piotrpersona
Created April 18, 2019 21:35
Show Gist options
  • Save piotrpersona/625a32e5567af805baf5ae5c392c1883 to your computer and use it in GitHub Desktop.
Save piotrpersona/625a32e5567af805baf5ae5c392c1883 to your computer and use it in GitHub Desktop.
Create fixup for topmost non-fixup commit - this will allow to stack fixups
# Git log:
#
# am3xn47 'fixup! Add file B'
# 302mx47 'Add file B'
# xn4273x 'Add file A'
NON_FIXUP_HEAD_COMMIT="$(
git log --oneline
| grep --invert-match 'fixup'
| head -1
| awk '{print $1}'
)"
echo "${NON_FIXUP_HEAD_COMMIT}" # Outputs: 302mx47
git commit --fixup "${NON_FIXUP_HEAD_COMMIT}"
# Git log:
#
# pcm48c3 'fixup! Add file B'
# am3xn47 'fixup! Add file B'
# 302mx47 'Add file B'
# xn4273x 'Add file A'
git rebase --interactive --autosquash "${NON_FIXUP_HEAD_COMMIT}~1"
# Git log:
#
# e90e323 'Add file B'
# xn4273x 'Add file A'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment