Skip to content

Instantly share code, notes, and snippets.

@innocarpe
Last active October 14, 2019 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save innocarpe/fade7f5fedc0b1917a0f14365b8a0bcc to your computer and use it in GitHub Desktop.
Save innocarpe/fade7f5fedc0b1917a0f14365b8a0bcc to your computer and use it in GitHub Desktop.
Fixup uncommited changes into target commit
#!/bin/bash
# Fixup uncommited changes into target commit
#
# `git cof` is a abbreviation of `git COmmit & Fixup rebase` :-)
#
# This will...
# 1. Commit uncommited changes with message "fixup! TARGET_COMMIT_HASH"
# 2. Fixup the commit meld into target commit with no interaction (non-interactive interactive rebase)
#
# Instruction
# 1. Move this file to ~/.gitsh/
# 2. Add directory path($YOUR_HOME_PATH/.gitsh) to environment variable file
# (like ~/.bash_profile or ~/.zshrc)
# (This would be like 'export PATH=${PATH}:/Users/YOUR_HOME_PATH/.gitsh')
# 3. chmod 0755 git-cof
# 4. Use the command 'git cof TARGET_COMMIT_HASH'
TARGET_COMMIT_HASH=$1
git commit -am "fixup! $TARGET_COMMIT_HASH"
GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash $TARGET_COMMIT_HASH~1 || git reset HEAD~1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment