31 ms·
Correct Git commits with git-autofixup
- Tobu 6y agogit-absorb is another implementation: - https://github.com/tummychow/git-absorb https://github.com/tummychow/git-absorb - https://lib.rs/crates/git-absorb https://lib.rs/crates/git-absorb
- NateEag 6y agoCan anyone give a comparison of the two from experience? I'm painfully familiar with the problem they solve and am delighted to discover they exist. I'd love some input about how they differ.
- Ambroisie 6y agoI have only used `git-absorb`, but one difference from reading the article is that it does its own analysis of your previous commits to choose what each line should `fixup`. Because of this, `git-absorb` can only fix up commits up to a specified base (10 commits earlier by default) when you use it.
- krobelus 6y ago> does its own analysis of your previous commits Not really; you can pass any commit ref to git-autofixup, and it will create commits only for commits since that ref. So it's for the user to decide :)
- krobelus 6y agoI have looked at both but only used git-autofixup. Some observations: - git-autofixup has a changelog - git-autofixup includes sober, technical documentation that actually explains how it works. OTOH, git-absorb has a great elevator pitch for users that are not so familiar with Git. - git-autofixup does not have unresolved bugs, unlike git-absorb - git-absorb creates fixup commits for the last 10 commits, which seems really odd. It's better to use symbolic references like @{upstream}, but it looks like they dont' support this yet? - git-autofixup is stable and mostly done software, while git-absorb has a sizeable list of todos - git-autofixup is written in Perl (like some tools in Git itself), making it easier to install than git-absorb which uses Rust. Then again, as author of this article, I'm obviously biased ;)
- NateEag 6y agoGreat information. Thank you!
- zimmski 6y agogit-autofixup definitely changed my daily development life.... I mostly use it with this Git alias ``` autofixup = !"autofixup origin/master --exit-code; test $? -lt 2 && GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash $(git merge-base HEAD origin/master)" ``` Works almost every time perfectly, and when not i always get a comment during a code review.
- jasonpeacock 6y ago> when not i always get a comment during a code review. Why during CR? Is the error not obvious to you? You should be able to check the results of your changes before pushing, right?
- zimmski 6y agoI/we do but sometimes you just overlook something especially if there are a lot of changes. But having someone else review what you do almost completely removes that problem. I usually do not look through all commits again when a basic review already happend and i "just" integrate the review comments. That is where for me personally these problems happen that git-autofixup is sometimes wrong but in over a few thousand commits in the last months this happend only thrice. Which for me just speaks for the tool IMHO. Ow the original author big time :-)
- torbiak 6y agoCool, I'm glad it's working out for you. Due to my workflow at my current job I haven't actually had much occasion to use it since writing it, so I'm not that confident about how good the hueristics are. Do you generally use the default --strict setting?
- samwestdev 6y agoSublime Merge do the same thing in just a couple of clicks, just saying
- globular-toast 6y agoI doubt it. There's an open feature request currently for adding fixup commits. This article goes a step beyond that. Are you sure you understood the article?
- ruffel 6y agoSelect two commits. Edit Commit -> Squash Selected Commits, ignoring new messages (fixup)
- globular-toast 6y agoThat's not a fixup commit, it's a rebase. It's missing the point of fixup commits which is to commit now and defer the rebase until later. It's also completely missing the point of the feature under discussion here which is to automatically decide which commit to squash the fix into.
- rollcat 6y agoIf you're an Emacs user, I must recommend magit (https://magit.vc/ https://magit.vc/) - the interactive rebasing (including squashing/fixups) is one of the best UIs (overall, not just git) I've seen in my life. I'd switch away from Emacs but magit keeps me hooked!
- shepmaster 6y agoDoes Magit have a similar feature to what is discussed in this article? Specifically “magically figure out which previous commit these changes should be combined with”?
- globular-toast 6y agoIt doesn't do it magically, but it makes it a lot easier to do. Easy enough that I've never really wanted a tool like this. Having said that, if autofixup works well it might be worth integrating it into magit via a plugin as it would certainly reduce the repetition.
- shepmaster 6y agoCould you share what your workflow would be? I’m assuming you put the point on the line you want to fix, then use Magit to start a rebase at the last commit that changed that line, then apply your changes, then continue? I’m a casual Magit user, so learning from other users would be very beneficial.
- jpeloquin 6y agoThat works. My habit is to make the fix, commit it as "!fixup whatever", start an interactive rebase, move the fixup commit just after the bad commit (M-↑), press f on the fixup commit to tell rebase to merge it with the bad commit, and run the rebase (C-c C-c). This is pretty much the same method as yours, but committing first means the fixup will still be there if you have to cancel & redo the rebase for some reason, such as unexpected and confusing merge conflicts.
- hashkb 6y agoFor this issue and so many others, everyone should just get comfortable with interactive rebase. Crutches like this trap you in this space of never really learning git. And that's a tragedy. All because you're impatient? Afraid?
- zimmski 6y agoLearning rebasing is one thing but wasting hours every week on rebasing because you are doing the same thing over and over again is another. When i do a one line fixup i just do not want to figure out the correct commit and then rebase i just want it to happen because i already know how i would rebase that: you just use git-autofixup or other similar tools discussed here to get it done.
- tomxor 6y agoIt's possible the other reason is trying to manipulate git history too frequently. Keep in mind this comes from a prolific git history abuser and rebaser... if hacking on a branch, a trail of messy commits is fine, it's your work in progress, it's also useful if you messed up otherwise you are forced to use reflog. Rebase when you are at the final stage of tidying things up and squashing commits down into a legible history, not on every single amendment... for this style of history rewriting rebase is perfect because you have the full power to rearrange rewrite and squash commits.
- zimmski 6y agoTotally agree. I guess what i am trying to say is that learning rebase is a must and powerful tool but if you are doing the same things again and again you should think about automating them and use your thinking-power and time for non-automated things.
- urxvtcd 6y agoI'd disagree. The longer the branch to rebase the larger the chance of conflicts occuring.
- hashkb 6y ago
- chrismorgan 6y agoAn excerpt from my ~/.gitconfig, showing a related approach (piggy-backing on git-revise): [alias] # Revise into the commit that last changed File rf = "!f() { if [ $# -eq 0 ]; then REV=\"$(git status --porcelain --untracked-files=no | sed '/^ /d;s/^.. //' | xargs -n1 git rev-list -1 HEAD --)\"; NUM_REVS=\"$(echo \"$REV\" | wc -l)\"; if [ $NUM_REVS -ne 1 ]; then >&2 echo Files in the index were not all last modified in the same commit; exit 1; fi; else REV=\"$(git rev-list -1 HEAD -- \"$1\")\"; shift; fi; git revise \"$REV\" \"$@\"; }; f" (This alias is three times as long as my next longest aliases, which are ports of Mercurial’s id, tip, incoming and outgoing commands.) This is more coarse-grained than the technique in this article, as it only goes down to the file level—because that was sufficient for me when I wrote the alias, and probably easier to implement. I’ve been vaguely contemplating trying git-autofixup and git-absorb for a while too, which include what are essentially more polished and powerful versions of my alias.
- taisalie 6y agoYou know that can go in $PATH/git-rf, right.
- chrismorgan 6y agoIf it grew much bigger I’d do that, but until it’s definitely too large, keeping all of this stuff in ~/.gitconfig is simpler, especially for sharing across heterogeneous machines.
- taisalie 6y agoYou can add a version-controlled directory to your PATH and put scripts in it. This can be in the same repository as your .gitconfig. So you can graduate aliases to scripts.
- chrismorgan 6y agoCopying a single file is regularly easier, and more flexible when working on machines not set up with your SSH keys or whatever.
- pjc50 6y agoHmm. This sounds like my workflow with gerrit, which goes like this: - each work item has its own branch. When pushed, gerrit turns this into a review. - a git alias, "alias.fixlast=commit -a --amend --no-edit" which amends the last commit to match the working directory Plus these configurations: branch.autosetuprebase=local branch.autosetupmerge=always pull.rebase=true The effect is that every branch I create off the main "develop" branch is automatically set up to rebase from that branch when I do "git pull". So when I get some review comments for review "xyz", I just do checkout - pull - make changes - fixup - push. Gerrit's workflow is slighly unusual in that each review must be a single git change, but it keeps a history of its own of previous changes you made to that review.
- yegle 6y agoThis is a lot like hg absorb. https://github.com/quark-zju/timepad/blob/master/assets/hgabsorb-note.pdf https://github.com/quark-zju/timepad/blob/master/assets/hgab... explained `hg absorb` pretty well with good visual.
- rurban 6y agoI'll keep using mine. It advances on magits autofixup by fixing up multiple files. And it checks if the commit was already published. git blame is not needed. https://github.com/rurban/home-bin/blob/master/git-cifixup https://github.com/rurban/home-bin/blob/master/git-cifixup
- alblue 6y agoI wrote my own tool for this which allows you to fix up a file based on the last time you changed that file, or on a specific commit. It will then execute an interactive rebase to that point as well as taking care of stashing and then restoring unrelated files. https://github.com/alblue/scripts/blob/master/git-fixup https://github.com/alblue/scripts/blob/master/git-fixup I like the idea of having the editor definition return “true” instead of showing it; I’ll have to add that later.