3 ms·
I have this one in mine: https://github.com/paul/dotfiles/blob/master/git/.gitconfig#L59-L60 https://github.com/paul/dotfiles/blob/master/git/.gitconfig#...
by psadauskas 2y ago
I have this one in mine: https://github.com/paul/dotfiles/blob/master/git/.gitconfig#L59-L60 https://github.com/paul/dotfiles/blob/master/git/.gitconfig#...
# make a fixup commit for the last time the file was modified
cff = "!f() { [ -n $@ ] && git add $@ && git commit --fixup $(git last-sha $@); }; f"
# Get latest sha for file(s)
last-sha = log -n1 --pretty=format:%h --grep 'fixup!' --invert-grep
Given a file like `git cff path/to/file.rb`, It'll find the last commit that touched that file, and make a fixup commit for it. Its great for the try-this-change-on-CI cycle: Change the Dockerfile, git cff Dockerfile, push, repeat, without it screwing up because you changed a different file while you were working on it.
- mdaniel 2y agoIt won't matter until it does, but $@ expands arguments into separate words but those expansions are themselves only word-preserved if the $@ is itself quoted. The [ will probably get away with what you want, but its use in $(git add) and $(git last-sha) almost certainly will not $ cat > tmp.sh <<'FOO' for a in $@; do echo "a=$a"; done echo for b in "$@"; do echo "b=$b"; done echo for c in $*; do echo "c=$c"; done echo for d in "$*"; do echo "d=$d"; done echo FOO $ bash tmp.sh 'alpha beta' $'charlie\ndelta' a=alpha a=beta a=charlie a=delta b=alpha beta b=charlie delta c=alpha c=beta c=charlie c=delta d=alpha beta charlie delta
- psadauskas 2y agoYeah, you're probably right. I guess I haven't run it on any files with spaces in the 6 years since I added it to my dotfiles.