3 ms·
I've you use rebase to rewrite history a lot I have found/developed a couple helpful commands (tested & working on Linux bash). Put those in your ~/.gitconfig:
by pizzapill 7y ago
I've you use rebase to rewrite history a lot I have found/developed a couple helpful commands (tested & working on Linux bash).
Put those in your ~/.gitconfig:
[alias]
fu = "!f() { local msg=\"fixup! $(git log --oneline -n1 | cut -d ' ' -f2-)\"; git commit -am \"${msg}\" && git rebase -i --autosquash HEAD~2; }; f"
fuc = "!f() { local msg=\"$(git log --oneline -n1 | cut -d ' ' -f2-)\"; if [[ \"${msg}\" != "fixup!"* ]]; then msg=\"fixup! ${msg}\"; fi; git commit -am \"${msg}\"; }; f"
xx = "!f() { git reset --hard && git clean -f -d; }; f"
From now on:
git fu = (git fix up) combines last commit and all staged changes into one commit with the last commit message
git fuc = (git fix up comment) commits all staged changes as a new commit with the last commit message, but prefixed with "fixup!". Except if the last commit message is already prefixed with "fixup!". Now you can work on the same thing but commit incremental steps. In the end you just do: git rebase -i master (or similar) and they will be all in one commit.
git xx = get rid off all unstaged/uncommited changes in current directory. Very destructive, very useful.
Last but not least. If you have a lot of "fixup!" or "squash!" commits and need to interactively rebase without autosquashing them do:
git rebase --no-autosquash -i master
- deleted 7y ago[deleted]