a git cheat sheet - Julia Evans
(cdn.masto.host)
from lemmyreader@lemmy.ml to linux@lemmy.ml on 17 Apr 2024 20:40
https://lemmy.ml/post/14581349
from lemmyreader@lemmy.ml to linux@lemmy.ml on 17 Apr 2024 20:40
https://lemmy.ml/post/14581349
cross-posted from: lemmy.ml/post/14581344
threaded - newest
Great cheat sheet, but has a really poor quality, even when I download it. It may be problem on my side. The original on mastonon has good image quality.
I’ve edited this post and linked to the original on Mastodon.
ccan you link the higher wuality one here in a comment, I don’t think It’s propagated.
<img alt="" src="https://lemmy.ml/pictrs/image/3791b43d-dbdb-4647-9306-46d27cc7a131.png">
cdn.masto.host/…/8cdf198fa52700f6.png
Still low quality.
EDIT: here is a link to a higher resolution. Link
Thanks!
You have to expand the image to its full size. Thumbnail images are downscaled so they use less data.
Gits motto should be “fuck around and find out”
More like “don’t fuck around but find out anyway”.
“Fuck around, have no idea HOW you fucked around, fuck around some more trying to fix it, find out how badly you’ve collectively fucked around”
That’s what the reflog is for!
More like “don’t fuck around (but of course the answer is some subset of
git checkout
(which is probably Turing-fucking-complete)), and find out anyway”.The only stuff I need, that should be easier
Commit -a isn’t easy?
Squashing is easy too, though no, there isn’t a “squash all” option, unless you’re working in a feature branch and check out master and git merge --squash branch: graphite.dev/guides/git-merge-squash
I’m sure there’s a way to commit to another branch without having it checked out, but that just sounds like a recipe for trouble.
And I have no idea how you’d manage to not have different ssh keys per user. You shouldn’t be reusing keys across accounts to begin with.
‘cherrypick’
I like this graphic, some of my favourites:
git log --oneline
is super useful for getting just a list of title of commits and nothing elsegit bisect
is a little known but extremely useful git archaeology command that automates binary searching for a regression.I just learned git bisect from https://ohmygit.org/! You run it, then checkout other commits all over the project, and mark them with git bisect good or git bisect bad. Then it paints all commits that led to the good one as good, and all the ones after the bad one as bad, so you just keep narrowing your window by playing checkout Jezzball until there’s only one commit left: the one that introduced the bad state.
The technical term is binary search.
Yeah but I didn’t know that term until I looked it up. Also OhMyGit didn’t cover using tests and automating it.
Definitely a useful tool and one you should’ve learned in a college algorithms course. Binary search backs a lot of high performance data structures
You’re gonna love this then:
I have a whole rc file full of shortcuts like this for Git and Docker.
Nobody loves pedantic escaped single quoting more than I.
Except for you wow.
Show us the
rc
.Reminder to read the official git book. It’s free and it’s useful. My dudes, stop pretending to understand your tools and actually learn them.
git-scm.com/book/en/v2
Madness!
LazyGit
For the lazy…
Love lazygit, am I better or worse a git now? Idk but I’m doing it much faster
tl;dr
You dropped
–force
Unless you’re rebasing or something, you should never need
–force
. It’s a good way to accidentally delete or overwrite a remote branch.I usually use the +syntax for force-pushing a specific branch:
git push origin +my_branch
I thought
-a
is shorthand to amend my bad<img alt="For those who like what I like" src="https://lemmy.kde.social/pictrs/image/25708dce-cb4b-4b0b-83d7-c7a90d171240.png">
Looking great. Thanks.
Is there anyone other than me who read
reflog
as re-flog the first time?Every time.
Always need to remind myself that
git
doesn’t go around flogging anyone.Some people use git to flog, though. See
Tangent are these VCS Rosetta Stones that might be interesting to some:
Darcs/Git/Mercurial: darcs.net/RosettaStone
Pijul/Git: nest.pijul.com/tae/pijul-for-git-users
I always forget how to do the delete distant branch with the : IIRC.