3 ms·
I made a simple script below I find useful that commits current changes then automatically rebases and squashes it with the previous commit, preserving the prev
by emacs28 4y ago
I made a simple script below I find useful that commits current changes then automatically
rebases and squashes it with the previous commit, preserving the previous
commit message. I find it useful for a way to quickly save current changes before switching
branches, or for easily backing up work before its worth making a new separate commit:
git add --all
git commit --fixup=HEAD~1
GIT_SEQUENCE_EDITOR="sed -i -re 's/^pick (.*)fixup! (.*)/fixup \1\2/'" git rebase -i --autosquash --autostash --keep-empty HEAD~2
- lelandfe 4y agoHN italics markup is mangling your code – indent the code block to fix :) like so! > save current changes before switching branches Also: why this over a stash? Stashing fundamentally just creates a hidden little commit with all your unstaged work on it. It does have one advantage over your approach, which is easily applying the work to another branch.
- emacs28 4y ago> indent the code block to fix :) Thanks! > Also: why this over a stash? I just like this better because with stash you have to do one more command (stash pop) to get the changes back after switching back to the first branch, but this way the changes are already there when you switch back.
- rjmunro 4y agoIsn't this the same as something like: git commit --all --amend With maybe a --no-edit thrown in?
- emacs28 4y agoYou know what you're right, the command git commit --all --amend --no-edit seems to do essentially the exact same thing, thanks!