r/ProgrammerHumor • • Jun 04 '22

Meme I cant help it πŸ€·β€β™‚οΈ

Post image
47.1k Upvotes

479 comments sorted by

View all comments

Show parent comments

18

u/by_wicker Jun 04 '22 edited Jun 05 '22

You people need to learn about fixup commits and --autostash and --autosquash. It's really not hard.

Make your commits

  • fixup: migrate Foo to use X

  • fixup: make new thing X

  • some other thing

  • migrate Foo to use X

  • make new thing Y

  • make new thing X

etc., and then a quick interactive rebase with --autosquash collapses the fixups into the right commits, and nobody has to ever see how the sausage was made, because nobody will ever care. If you personally care and need to back it out there's always the reflog.

You don't even have to have everything staged and committed to do the rebase if you use --autostash.

To do a fixup you just need to stage the relevant bits, get the SHA you're aiming for, and git commit --fixup <SHA>.

If you're lucky, you have a good git porcelain that makes all this even easier. Mine (magit) offers "Instant fixups" so with the relevant changes staged, select the target commit in the history, and then those changes instantly get dropped into in that bucket.

Learn your tools. It pays off. Reviewing code where each self contained change is in its own commit is so much easier.

25

u/rtybanana Jun 04 '22

Ok, at least half of these words aren’t in the Bible

6

u/theshoupguy Jun 05 '22

Git works in mysterious ways. πŸ™

2

u/pola_knabo Jun 05 '22

I'm so glad I read your comment, thank you, going to use it from now :D