keis / Git Fixup
Programming Languages
Projects that are alternatives of or similar to Git Fixup
git-fixup
Fighting the copy-paste element of your rebase workflow.
git fixup <ref>
is simply an alias for git commit --fixup <ref>
. That's
just a convenience feature that can be also be used to trigger tab completion.
The magic is in plain git fixup
without any arguments. It finds which
lines/files you have changed, uses git blame/log to find the most recent commits
that touched those lines/files, and displays a list for you to pick from. This
is a convenient alternative to manually searching through the commit log and
copy-pasting the commit hash.
Install
On OS X you can install this script with homebrew
brew install git-fixup
On Arch linux you can install from AUR using yaourt or a similar tool
yaourt git-fixup
For most other systems (as long as they include install
and make
) you can
install by cloning this repo and running make
git clone https://github.com/keis/git-fixup.git
cd git-fixup
make install
make install-zsh
Or if you don't want to deal with any of that you can simply download the
scripts in anyway you like and make sure to put the program and completion
script into your $PATH
and $fpath
respectively.
Usage
git-fixup [-s|--squash] [-f|--fixup] [-c|--commit] [<ref>]
For this tool to make any sense you should enable the rebase.autosquash
setting in the git config.
# Select the changes that should be part of the fixup.
$ git add -p
# Output a list of commits that the staged changes are likely a fixup of.
$ git fixup
# Create a fixup!-<commit> of the given ref. If you have installed the zsh script
# you can cycle through the list of fixup candidates with tab completion.
$ git fixup <ref>
# Commit rebased into the selected commit as a fixup.
$ git rebase -i ...
Options
-s, --squash
Instruct git-fixup
to create a squash!
commit instead of a fixup!
commit.
Squashing gives you the opportunity to edit the commit message before the commits are squashed together.
Default action can be configured by setting fixup.action
-f, --fixup
Instruct git-fixup
to create fixup!
commit (This is the default).
Default action can be configured by setting fixup.action
-c, --commit
Instead of listing the suggested commits show a menu to pick a commit to create a fixup/squash commit of.
A default menu is provided that is intentionally very
simple and with no advanced features. Instead of using it you can tell git fixup
to use an external tool for the menu by defining a command line via
either the fixup.menu setting in the git config or the GITFIXUPMENU
environment variable (the latter overrides the former).
# Use fzf as a menu program
$ GITFIXUPMENU=fzf git fixup -c
This option can be enabled by default by setting fixup.commit in the git config.
--no-commit
Don't show the commit menu even if previously instructed to do so.
Configuration
git-fixup
uses configuration from the ENVIRONMENT or from git config
fixup.action
Or GITFIXUPACTION
Decides if the default actions will be fixup
or squash
.
fixup.commit
Or GITFIXUPCOMMIT
Decides if the commit menu should be displayed instead of the commit list by default.
# Enable --commit for all my projects
$ git config --global fixup.commit true
fixup.menu
Or GITFIXUPMENU
Sets the command that will be used to display the commit menu. If not set a simple [default menu](default menu] will be used.
See External menu for more details and a more advanced example.
Tab completion
Tab completion for zsh is implement and the suggestions for the tab completion is the suggested fixup bases as generated by running the tool without any arguments.
To be able to tab complete the command itself add a line like this to your zsh configuration::
zstyle ':completion:*:*:git:*' user-commands fixup:'Create a fixup commit'
External menu
In order to use an external tool for display the commit menu, you need to
either define the fixup.menu setting in the git config or set the
GITFIXUPMENU
environment variable with the command for the menu. The menu
command must receive as input the lines as the options for the user and return
the selected line to the standard output.
The following example is a fragment of a git config that makes git fixup --commit
display a nice menu with fzf:
[fixup]
menu = fzf --height '60%' \
--bind 'tab:toggle-preview' \
--preview 'git show --color {+1}' \
--preview-window=up:80% \
--prompt 'Select commit: '
The default menu
If you have not configured an external menu, the default menu is used. See the example below:
$ git fixup -c
1) 500be603c66040dd8a9ca18832d6221c00e96184 [F] Add README.md <[email protected]>
2) ddab3b03da529af5303531a3d4127e3663063e08 [F] Add index.js <[email protected]>
Which commit should I fixup? <your-selection>
Here <your-selection>
should be the number of the desired commit in the list.
You can use q
to abort the operation and h
to see a help message for the
menu.
If the commit title alone is not enough for you to decide, you can use show <number>
to call git show
on the <number>
-th commit of the menu.
Changelog
See CHANGELOG.md