• 0 Posts
  • 2 Comments
Joined 1 year ago
cake
Cake day: June 15th, 2023

help-circle
  • jks@feddit.nltoLinux@lemmy.mlYour best terminal aliases
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Not exactly an alias but a short script. First, get git-revise which is a replacement for git rebase, and fzf if for some reason you don’t have it yet. Then make a script in your ~/.local/bin called git-f or whatever you’d like:

    #!/bin/bash
    REF=${1:-origin/main}  # adjust to your favorite trunk branch name
    COMMIT=$(git log --pretty=oneline ${REF}.. \
             | fzf --preview "git show -p --stat {+1}" | cut -d' ' -f1)
    if [ -n "$COMMIT" ]; then
        exec git revise "$COMMIT"
    else
        exit 1
    fi
    

    Now hack away in a branch, make some commits, and at some point you will realize you want to modify an earlier commit. Use git add -p to add the relevant lines, but then instead of making a fixup commit just type git f and pick the target commit from the list.