Live data from Hacker News

Correct Git commits with git-autofixup

symflower.com

11–20 of 67 posts

Re: Correct Git commits with git-autofixup

#11
post #3

git-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.

> 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?

I/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 :-)

Re: Correct Git commits with git-autofixup

#12
post #5

If you're an Emacs user, I must recommend magit ( 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!

Does 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”?

It 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.

Re: Correct Git commits with git-autofixup

#14
post #9
post #7

For 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?

Learning 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.

It'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.

Re: Correct Git commits with git-autofixup

#15

Earlier quoted context omitted.

Does 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”?

It 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.

Could 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.

Re: Correct Git commits with git-autofixup

#16
post #5

If you're an Emacs user, I must recommend magit ( 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!

Does 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”?

Magit incorporates git-autofixup directly via `magit-commit-autofixup`; also available is `magit-commit-absorb` for git-absorb.

Re: Correct Git commits with git-autofixup

#17
post #14
post #9

Earlier quoted context omitted.

Learning 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.

It'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 h…

Totally 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.

Re: Correct Git commits with git-autofixup

#18
post #14
post #9

Earlier quoted context omitted.

Learning 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.

It'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 h…

I'd disagree. The longer the branch to rebase the larger the chance of conflicts occuring.

Re: Correct Git commits with git-autofixup

#19
An 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.

Re: Correct Git commits with git-autofixup

#20
post #9
post #7

For 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?

Learning 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.

Practice. You'll get better and faster. I do it tens of times daily and each fixup takes ten or fifteen seconds.
Post reply on HN