this post was submitted on 01 Mar 2024
91 points (87.0% liked)

Programming

17669 readers
211 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 2 years ago
MODERATORS
 

As aliases

alias g-log="git log --graph --format='format:%C(yellow)%h%C(reset) %s %C(magenta)%cr%C(reset)%C(auto)%d%C(reset)'"
alias g-history='gitk --all &'
alias g-checkout='git checkout $(git branch --sort=-committerdate --no-merged | fzf)'
alias g-commit='git citool &'
alias g-amend='git citool --amend &'
alias g-rebase='git rebase --interactive --autosquash'
alias g-pull='git pull --verbose --rebase'
alias g-pushf='git push --verbose --force-with-lease'
alias g-status='git status --ignored'
alias g-clean='git clean -fdx && git reset --hard && git submodule foreach --recursive git clean -fdx && git submodule foreach --recursive git reset --hard'
all 44 comments
sorted by: hot top controversial new old
[–] [email protected] 74 points 9 months ago (2 children)

What in the absolute fuck is in that thumbnail??

[–] [email protected] 69 points 9 months ago (3 children)

These AI generated images for articles bother me a lot.

[–] [email protected] 8 points 9 months ago

I think they are pretty funny. They don't matter, it's just a nice little colorful image that has to be there. There is no information transported or displayed incorrectly, because there is none 😄

[–] [email protected] 8 points 9 months ago

What annoys me the most is that AI image generators make it so easy to make images and yet despite that they're still too lazy to spend 2 seconds to look at the image and check if it's crap or not. It would literally take them only a couple of minutes to tweak the prompt and regenerate some more images.

[–] [email protected] 7 points 9 months ago* (last edited 9 months ago)

Agreed. I also see them all over youtube videos and stuff and I just can't keep reading/watching. Its not like an ideological thing, i don't hate generated art. I just find it so distracting.

[–] [email protected] 25 points 9 months ago (3 children)

I'm gonna be completely honest. I don't truly get all the inner working of git. I'm a senior DevOps Engineer and been using git for a decade, but is git is simular to sed or awk for me. I know how to do what I want really well but when shit goes wrong, I'm flying by the seat of my pants.

A lot of times, I just know what to do to fix things because it's rote memory with substitutions. But if you needed me to explain upstreams and rebases in actual detail, I'd be in trouble. But it rarely becomes an actual problem to the level where I'll dedicate time to learning all the advanced stuff.

That said, I've learnt that most senior people also just pretend they get it all but instead are just relying on rote memorization and basic concepts. Anyone else here in the same camp of being a fraud with git?

[–] [email protected] 7 points 9 months ago

Anytime I’m about to get fancy with git I have to stop and remember that I’m an idiot and am probably not doing something else right.

[–] [email protected] 5 points 9 months ago

The fact that you have to kind of understand how git works under the hood to really unlock its full potential is a definite design flaw of the tool, but given its ubiquitous use in our industry, I encourage you to check out how git works under the hood. Once you learn the underlying concepts, you reach a whole new level of proficiency with git, no longer having to just get by, and instead you get to thrive.

[–] otto 4 points 9 months ago

I had the same feeling until I started using gitk. I always have a gitk window open and press F5 to reload, so it shows me the state of everything after I've run git commands. Now I grasp everything much better.

[–] [email protected] 17 points 9 months ago (4 children)

If you need anything more complex than cherrypick, you already screwed up big time.

[–] lysdexic 10 points 9 months ago* (last edited 9 months ago) (3 children)

If you need anything more complex than cherrypick, you already screwed up big time.

I think this is a clueless comment. You can use Git to greatly improve your development workflow if you dare going beyond the naive pull/commit/push workflow.

Take for example interactive rebase. It let's you do very powerful stuff such as changing the order of commits in a local branch and merge/squash contiguous commits. This unlocks workflows such as peeling off bugfix and cleanup commits from your local feature branch without having to switch branches. I'm talking about doing something like:

a) - you're working on your task, b) - you notice a bug that needs fixing, c) - you fix the bug and commit your fix, e) - you continue to work on your task, f) - you notice a typo in your bugfix code, so you post a fixup commit. g) - you post a few commits to finish your task, h) - you noticed your bugfix commit didn't had the right formatting, so you post a couple of commits to lint your code both in your bugfix commits and task.

When you feel you're done, you use interactive rebase to put everything together.

a) you reorder your commits to move your bugfix commit to the top of your local branch, followed by the typo fixup commit and the linter commit. b) you mark both the typo and linter commits as fixup commits to merge them with the bugfix one, c) you post a PR with the single bugfix commit, d) you finally post a PR for your task.

Notice that thanks go git interactive rebase you did not had to break out of your workflow or do any sort of context switch to push multiple PRs. You just worked on things you had to work, and in the end you just reorganize the commit history in your local branch to push your work.

Is this what you call "screwed up big time"?

[–] [email protected] 7 points 9 months ago (2 children)

That sounds like a solution in desperate need for a problem.

All the "problems" you described boil down to "switching branches is evil".

[–] [email protected] 1 points 9 months ago (1 children)

It doesn't disrupt my workflow to switch branches and it's much faster than some ugly rebase

[–] lysdexic 1 points 9 months ago (1 children)

It's ok if you don't feel a need to change your persona workflow.

Nevertheless I'm not sure you understood the example, so I'm not sure you fully grasp the differences.

The whole point of my example was to point out the fact that, thanks to interactive rebase, you do not even need to switch branches to work on multiple unrelated PRs. You can just keep going by doing small commits to your local feature branch and keep doing what you're doing. In the end all you need to do is simply reorder, squash, and even drop commits to put together multiple PRs from commits that are built upon each other.

Simple, and straight to the point.

[–] [email protected] 2 points 9 months ago (1 children)

I think I understood the example; I think it's faster to switch branches for the bug-fix than to reorder those commits later

[–] lysdexic -3 points 9 months ago (1 children)

See, I don't think you understood the example. The commits built upon each other (bugs are fixed while you work on the task, and to work on your task you need the bugs to be fixed) and reordering commits not only take no time at al but they are also the very last thing you do and you have to do the just once.

[–] [email protected] 6 points 9 months ago* (last edited 9 months ago) (1 children)

Oh, okay. I've never encountered a situation where I needed that bug fixed for the task but it shouldn't be fixed as part of the task; if they're touching the same functionality like that I really don't see the need for two PRs. But sure, sounds helpful in that really niche case.

[–] lysdexic -4 points 9 months ago* (last edited 9 months ago) (1 children)

Oh, okay. I’ve never encountered a situation where I needed that bug fixed for the task but it shouldn’t be fixed as part of the task;

So you never stumbled upon bugs while doing work. That's ok, but others do. Those who stumble upon bugs see the value of being able to sort out local commits with little to no effort.

Also, some teams do care about building their work on atomic commits, because they understand the problems caused by mixing up unrelated work on the same PR, specially when auditing changes to track where a regression was introduced. You might feel it's ok to post a PR that does multiple things like bumping up a package version, linting unrelated code, fixing an issue, and post comments on an unrelated package, but others know those are four separate PRs and should be pushed as four separate PRs.

if they’re touching the same functionality like that I really don’t see the need for two PRs.

That's ok, not everyone works with QA teams. Once you grow over a scale where you have people whose job is to ensure a bug is fixed following specific end to end tests and detect where a regression was introduced, you'll understand the value of having tests that verify if a bug is fixed, and only afterwards proceed with changing the user-facing behavior. For those with free-for-all commits where "fixes bug" and "update" show up multiple times in their commit history, paying attention to how a commit history is put together is hardly a concern.

[–] [email protected] 3 points 9 months ago* (last edited 9 months ago)

So you never stumbled upon bugs while doing work

That's not what I said.. Either the bug is related to the task, or it isn't. If it's not related to the task, there's no reason to fix it on the same local branch either.

Also, some teams do care about building their work on atomic commits, because they understand the problems caused by mixing up unrelated work on the same PR, specially when auditing changes to track where a regression was introduced. You might feel it's ok to post a PR that does multiple things like bumping up a package version, linting unrelated code, fixing an issue, and post comments on an unrelated package, but others know those are four separate PRs and should be pushed as four separate PRs.

Well, these things don't meet the standards of your earlier example at all. Linting unrelated code and posting comments on an unrelated package clearly aren't needed for someone to work on the main issue fix they're doing. If it's unrelated code you again lose nothing by switching branches to do the work.

[–] [email protected] 0 points 9 months ago

Yes, why are you wasting time with all that. No one uses the commit history to the level that any of that matters. If it does, you ci flow is the problem.

[–] [email protected] 7 points 9 months ago (1 children)

I disagree wholeheartedly with this. I consider the commit history as documentation for pull requests and for future history, and as such I make liberal use of interactive rebasing to curate my commits.

Rebasing in general is one of those things that I picked up fairly late, but now it's essential to my git workflow.

[–] technom 3 points 9 months ago (1 children)

What's ironic is that rebases aren't as hard as many consider it to be. Once you've done it a couple of times, you just do it everyday as easily as you commit changes.

[–] [email protected] 1 points 9 months ago

Absolutely. I think it helps a lot to understand the mechanics of git and rebasing, but after a few times it just makes more sense than merging, really.

[–] NostraDavid 2 points 9 months ago

I've been using git for some three years now - never used Cherrypick (not consciously, anyway).

[–] [email protected] 1 points 9 months ago* (last edited 9 months ago)

If you're doing more complex stuff all the time then yes that's an indication of a problem, but despite your best efforts, complex situations or screw ups do happen and it's good to know how to fix them, especially if you're a senior dev that needs to help the rest of the team and resolve conflicts between feature branches. The whole team can't be perfect all the time.

Also most of the tips in the article aren't even about branch management and more about optimizations for huge projects or introspection into the history of large projects.

[–] cd_slash_rmrf 14 points 9 months ago* (last edited 9 months ago) (1 children)

this article suggests shell allowed, but git also has a built-in feature for aliases itself. I prefer these as it allows you to keep using the git command normally (more consistent when you tend to use history search/auto-suggestions heavily).

running git config --global alias.st status, for example, will allow you to run git st as an alias for typing out the full git status (you can also manually add aliases to your ~/.gitconfig).

[–] otto 4 points 9 months ago

I just prefix all my git aliases with g-. So for status I type g-s<tab>.

[–] [email protected] 7 points 9 months ago (2 children)
[–] [email protected] 11 points 9 months ago

senior dev don't debug 😎

[–] otto 2 points 9 months ago

You need bisect only as a last resort. Effective use of git blame, git log -p -S <keyword> etc has always been enough for me. Also, the projects I work with take 10+ minutes to compile even when cached, so doing tens of builds to bisect is much slower than just hunting for strings in git commits and code.

[–] [email protected] 6 points 9 months ago

Just be lazy, it’s the best of both worlds.

[–] [email protected] 6 points 9 months ago

I always just use git commit -m foo.

But thanks, never heard of citool, thats a new one.

[–] [email protected] 2 points 9 months ago* (last edited 9 months ago) (1 children)

Thank you for pasting the contents in the post. I refuse to click a link to a scummy site that uses AI art.

[–] [email protected] 5 points 9 months ago (1 children)

Nasty thing to say on account of the author of the article being the OP as well.

[–] [email protected] 0 points 9 months ago

oof :( sorry to see fellow lemmings falling victim to the AI movement.

[–] LinearArray 2 points 9 months ago

Wow this is pretty helpful, thanks for sharing