4 ms·
Interesting project... in the hopes of maybe nerd-sniping you (or having someone tell me where it already exists), I'll tell you the story I'd really like a sol
by kenmacd 3y ago
Interesting project... in the hopes of maybe nerd-sniping you (or having someone tell me where it already exists), I'll tell you the story I'd really like a solution to but can never seem to find time to build:
I have 5 un-pushed commits. I missed a 1-line change to that first one. I add that one line change to staging (gitui/lazygit/whatever), then I want to `git commit --fixup=COMMIT`. Finding that COMMIT is always a manual process for me for two reasons.
First I have to find the commit to which it applies. This commit is almost always the commit that changed the same line, or added lines around it, or something similar. I guess you could say it's the commit with the closest proximity to the change I'm adding.
Second I have to find the hash of that commit. If I've since done something like an autosquash rebase then it'll have changed. I generally end up using the mouse to do a copy/paste at this point.
Why not skip the fixup commits and just rebase right then, you might ask. Well the commits are signed, and signing requires tapping my yubikey for each commit after that.
I would really like to be able to do something like `git commit --I'm-an-idiot-and-missed-this-so-please-apply-a-fixup-to-the-proper-commit`, and have it do the figuring out for me.
- brantonb 3y agoI can’t solve the whole problem for you, but you can `git commit --fixup HEAD~4` if you know it’s 5 commits back. No need to figure out the hash. `HEAD^^^^` would also work — sometimes if I have to repeatedly fixup the same commit, adding an additional ^ to a previous command is easiest.
- fla 3y agoI usually solve this by commiting my fixup in a dummy commit, then do a rebase -i HEAD~n where n is the number of commits I want to look back at. Then during the rebase I just move my commit below the one that seem the most appropriate and mark it for squash. Execute the rebase. Done
- Seb-C 3y agoWow, I never realized that changing the order of commits in an interactive rebase was a legit operation. Thanks for the tip!
- shaftway 3y agoAnother way to handle this if you haven't made the change yet is to do a `git rebase -i head~4` (or however far back) and mark the place where the change needs to happen as "edit". Make your change, add the file, then `git rebase --continue`. If you've already made the change but haven't committed it, you can stash it before doing the rebase, then pop the stash while editing that commit.
- graton 3y agoIf you have `fzf` installed you might try this alias. frbi = "!f() { git rebase -i $(git log --pretty=oneline --color=always | fzf --ansi | cut -d ' ' -f1)^ ; }; f" I do: `git frbi` (which in my mind means Fzf ReBase Interactive) Then I can easily scroll up to the commit I want to start the rebase on.
- mklein994 3y agoNot as quick as you're asking for, but what I do, after running "git log" to jog my memory of what the commit message was, is this: git commit --fixup=':/message regexp' This will find the youngest commit where the message matches the "message regexp" pattern. See also: https://git-scm.com/docs/gitrevisions https://git-scm.com/docs/gitrevisions
- spost 3y agohttps://github.com/tummychow/git-absorb https://github.com/tummychow/git-absorb Does a very nice job of this for me.
- kenmacd 3y ago>> git absorb will automatically identify which commits are safe to modify, and which staged changes belong to each of those commits. It will then write fixup! commits for each of those changes. This looks like exactly what I wanted. Thank you!
- parentheses 3y agoI want this too. We just shipped "amend from status" allowing you to push staged files into the HEAD commit. It's only a small step to add selection of the commit to amend. Feel free to make a PR. If not, I'll probably queue it up to work on at some point.
- dceddia 3y agoI do this a lot in lazygit, or at least something that sounds similar: I’ve got some changes, I stage them by pressing spacebar (or hitting enter and adding lines in a more granular way), and then switch to the Commits tab, arrow down to the one I want to add this change to (all the unpushed ones are red) and hit A to amend.
- williamdclt 3y agoLazygit allows you to easily « add » your stated changes to any commit (doing a rebase under the hood). Stage stuff, find the commit (the UI helps to quickly find the right commit) and press « a » for amend. It’s not quite as automatic as you describe, but it’s super quick if you vaguely know what commit you want to amend and there’s no magic happening: just a good ui
- kenmacd 3y agoTy. I've seen similar in other tools, and I agree that it's super quick... unless you sign your commits with a key that requires a physical touch of a yubikey. Then it's <tap> <wait> <tap> <wait> for every commit that comes after the one you just modified.
- shambulatron 3y agoThis was my bugbear for a long time too, and then I found fzf-git.sh (actually its PowerShell equivalent, PSFzf). fzf (absolutely incredible tool with many uses) gives you fuzzy searching of anything you care to name, and fzf-git combines this with shell key bindings to let you pop up a fuzzy-searchable list of branches/commits/tags/whatever while typing your fixup command, then paste the object you select into your in-progress command line. No more counting commits in log output to know how many ^ to put after HEAD, or copying out segments of commit SHAs!
- jesseduffield 3y agoLazygit maintainer here: I've found myself in your shoes quite a bit (without the commit signing part) and a few weeks ago I put up a draft PR where if a file is selected, it highlights the commits that touch that file. Typically you want to amend the most recent commit that changed the file and typically that commit is visible without needing to scroll. But I haven't spent much time thinking about what the ideal UX is, how to activate it, etc. PR: https://github.com/jesseduffield/lazygit/pull/2654 https://github.com/jesseduffield/lazygit/pull/2654
- hashhar 3y agoBoy have I got the thing for you. git absorb - https://github.com/tummychow/git-absorb https://github.com/tummychow/git-absorb The way to work with it is: git add file1 git commit -m "Fix some bug in file1" git add file2 git commit -m "Add a feature flag for file1" # Oh no, first commit was borked, need to fix it git add file1 git absorb # this will now automatically create one or more fixup commits git rebase -i --autosquash $(git merge-base master) # voila, tidy history and each commit works