-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add a Git cheat sheet #2049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gh-pages
Are you sure you want to change the base?
Add a Git cheat sheet #2049
Conversation
There are Mermaid diagrams... maybe they are Good Enough™️? gitGraph
commit id: "A"
commit id: "B"
branch topic
commit id: "D"
commit id: "E"
checkout main
commit id: "C"
And while Hugo does not support Mermaid diagrams out of the box, it is relatively easy to integrate them, I did something similar yesterday. |
I didn't know you could integrate Mermaid into Hugo in that way, that's cool! Maybe we could integrate Graphviz in a similar way -- I find the Mermaid diagrams aren't information dense enough (those labels are so small!), but Graphviz can do it easily (preview link) |
Apparently we could! I just found https://huanglei.rocks/posts/add-math-and-dot-for-hugo/ which talks precisely about that... Unfortunately, it was quite outdated, and it left a lot of gaps to figure out. And then I fell into the trap that I wanted to use codeblocks, but git-scm.com is maintained as But I'm no giver-upper, so I battled it, and I won! You can see the proof-of-concept here: https://dscho.github.io/git-scm.com/about/small-and-fast (commits: gh-pages...dscho:git-scm.com:poc-diagrams). For posterity, here is a screenshot: ![]() The upper diagram uses Mermaid, the lower one Graphviz dot and neato. I agree that Graphviz is more powerful than Mermaid, but it comes at the price of 1.4MB vs 25kB... |
Nice, I hadn't even thought about the issues with using codeblocks in HTML so it's really cool to see the solution. Re the bundle sizes: it does look like the CDN version of Mermaid is smaller than viz.js (it downloads a bunch of extra code after the 25K load: from adding up the numbers in my head it looks like it's about 500K of code over maybe 30 different HTTP requests). But I'm not sure if it's possible to actually get that 500K size without using the CDN, and I'm also concerned about how dynamically loading 30 different JS files would impact loading files. Here's a discussion about large Mermaid bundle sizes. https://github.com/orgs/mermaid-js/discussions/4314 I tried to get a single JS file that we could host ourselves and the sizes came out to 1.4MB for viz.js and 2.5MB for mermaid.js.
Here's a screenshot of the Mermaid CDN loading all of its JS chunks: |
Oh wow, mermaid has transitive dependencies? That's horrible! And yes, while 1.4MB is not exactly light-weight, it is at least possible. Obviously, we could consider a server-side rendering approach that generates an file containing a list of files that had I think I would prefer that approach to requiring a 1.4MB JavaScript library just to render the diagrams. |
I agree that 1.44MB feels like too much, especially since the SVG files are only 3K each. I'm a bit worried that the Nokogiri approach would result in a really long build time while tweaking the diagrams though. I think it might be faster to have a directory of
I've already been using completely separate version of the files (just a standalone |
Oh, I hope you're using a sparse checkout? In such a checkout, even on Windows the Hugo build times are somewhat bearable. Here is a run in the worktree in which I developed the Graphviz patches:
It's this fast because I exclude all $ git sparse-checkout list
assets
content
data
hugo.yml
layouts
script
static
tests
Right. Maybe the best approach would be to use that 1.44MB file by default, but also write the list of |
@dscho I tried switching to a sparse checkout again (not sure why I couldn't get it to work last time) and your |
Very nice! BTW I worked some more on the idea that I mentioned earlier, to pre-render the diagrams as a post-processing step after Hugo. Here is the result: gitgitgadget/gitgitgadget.github.io@266bccc. You can see it in action here: https://dscho.github.io/gitgitgadget.github.io/architecture (this has the diagrams I added in gitgitgadget/gitgitgadget.github.io@af226bb pre-rendered as inline SVGs). |
I've updated my And I am really glad that I made those changes. When I loaded https://dscho.github.io/git-scm.com/about/small-and-fast into my browser, there was a noticeable delay before the Mermaid diagram was shown (but the Graphviz-generated SVG was displayed immediately, as one would expect). Makes for a much nicer user experience. |
c051d8f
to
008916c
Compare
Awesome! I've made a bunch of updates and now I'd love comments on the content or styling of the page. Here's the current version again: https://jvns.github.io/git-scm.com/cheat-sheet I built the cheat sheet mostly from the commands I use in my personal Git workflow (other than One of my goals for the cheat sheet is to be a little bit more of a "complete" cheat sheet than the one GitHub provides -- for example I find it hard to imagine living without something like I'm also using a sans-serif font right now, should probably move it back to the site font. I'll try to stop force pushing changes at the point to make the changes easier to track. |
Would also be nice to link your cheat sheet at the top as a downloadable PDF version of this. |
Yes! I'll stop cluttering this ticket with Graphviz stuff. One thing that I noticed is that the dark mode probably needs slight adjustments. The content is awesome! The "new" way to get and set config variables is Do we want to get a bit more into the weeds like using the power of Git aliases? I am thinking about things like
You probably don't want _this_ alias, though[alias]
edit-alias = "!\ndie() {\n\techo \"$*\" >&2\n\texit 1\n}\n\nedit_alias() {\n\tl_opt=--global\n\tcase \"$1\" in\n\t-l|--local)\n\t\tl_opt=--local\n\t\tshift\n\t\t;;\n\t-g|--global)\n\t\tl_opt=--global\n\t\tshift\n\t\t;;\n\tesac\n\ttest $# = 1 || die \"Need the name of an alias\"\n\n\ttmpdir=$(mktemp -d) &&\n\ttrap \"rm -rf $tmpdir\" EXIT &&\n\ttmpscript=\"$tmpdir/$1.sh\" &&\n\tgit config $l_opt --default '!\n# This is a new shell alias; If you do anything complicated, consider\n# implementing one or more shell functions, and end in a function call\n# whose parameters will be the command-line parameters passed to that alias.\n\ndie() {\n\techo \"$*\" >&2\n\texit 1\n}\n\nhello() {\n\ttest $# = 1 || die \"Need exactly one parameter\"\n\techo \"Hello, $1!\"\n}\n\nhello' alias.\"$1\" >\"$tmpscript\" &&\n\t\"$(git var GIT_SEQUENCE_EDITOR)\" \"$tmpscript\" &&\n\tgit config set $l_opt alias.\"$1\" \"$(cat \"$tmpscript\")\"\n}\n\nedit_alias" 😆
Oh, please consider keeping using the sans-serif font! For cheat-sheets, I prefer them, so I'd vote to keep using it. |
Oh @schacon, why do you want to nerd-snipe me into derailing the discussion with technically challenging automation again? 🤣 |
You may be interested in tl;dr I would highly recommend showing off |
@jvns the dark mode colors look pretty good, except of course the SVGs: ![]() I could try to hack on that, in addition to the PDF... |
I like the idea of including a downloadable PDF version, and I'd also like to be able to keep it updated as the page evolves. Maybe with a print stylesheet somehow? I'm not sure how easy it would be to get something that looks good though. I tried a more basic approach to displaying the SVG in dark mode. |
assets/sass/cheat-sheet.scss
Outdated
svg { | ||
height: auto; | ||
width: 100%; | ||
border-radius: 5px; | ||
padding: 5px; | ||
box-sizing: border-box; | ||
background: var(--svg-bg); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit concerned that this might affect other SVGs than the Graphviz ones we generate, e.g. the company logos on the front page (which seem to be designed to look good in both dark/light mode?).
Here is an alternative that I would like to offer: jvns#1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of using invert
! This selector is .cheat-sheet .item svg
so it's already very specific, it won't affect other SVGs on the site.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed that it was nested. Great!
@jvns I'm catching up on this PR and it's amazing. Exactly the type of content we need for "Learn"/"Getting started".
@dscho I guess this was already settled, but I prefer server-side rendering. Please don't render them on the client-side, it doesn't make sense to bloat the user with this load (even though it's only floppy of extra data to transmit). I would even consider to check-in the generated svgs (similar to what we do with the man pages). We could have a Action that checks if the svgs are up-to-date. About Mermaid and Graphviz, I like Graphviz more, visually. They fit the aesthetic of the site better, and are more dense as Julia pointed out. ![]() @jvns I love how you've put your signature into this. 💜
@dscho I'm happy you are taking the bait... 🤣 Anyhow, that can happen outside this PR. |
https://dscho.github.io/git-scm.com/cheat-sheet.pdf (generated via jvns/git-scm.com@cheat-sheet...dscho:git-scm.com:printable-cheat-sheet). |
@dscho That looks amazing! And I love the And it's great you've improved the printiness (or is it printability?) of any page. Although I've noticed man pages for example |
@To1ne not by coincidence, and when you asked, I did not have an idea. But now I do: git-scm.com/assets/sass/layout.scss Line 23 in 802cbb4
Overriding that (as I found out via straight-forward, if laborious bisecting) removes those relative pages. Speculation as to whyI expect this to have something to do with the many layers of abstraction in the HTML: I overrode it in a Range-diff
|
Hey @jvns I did it again, I only added distraction from the actual topic in this PR. To make amends for that, let me propose the following plan:
How does that sound? |
@dscho I think the print version of the cheat sheet looks nice (love |
## Changes - This adds support for Graphviz diagrams and replaces the `.png`s in https://git-scm.com/about/distributed with scalable versions. ## Context Over in #2049, we discussed various options how to add elegant diagrams, and settled on Graphviz ones. I broke this out so that I don't have to derail the discussion about the cheat sheet anymore. The solution presented here uses [`viz.js`](https://viz-js.com/), a WebAssembly version of Graphviz. Since it weighs a bit much (1.4MB), this is used client-side only when developing the page locally; When the site gets deployed, the SVGs are "pre-rendered", i.e. generated and inserted in place of the `<pre class="graphviz">` blocks. To demonstrate this new feature, I replaced the diagrams in https://git-scm.com/about/distributed with Graphviz ones: | before | after | | - | - | |  |  | |  |  | |  |  | The changes of this PR can also be seen in action in my fork: https://dscho.github.io/git-scm.com/about/distributed
Just rebased on the graphviz changes! How about we can merge this before the printable cheat sheet work is done and then discuss that in a separate PR? (edit: rebased & force pushed the wrong thing by accident but should be fixed now) |
bcff0e8
to
c368fd5
Compare
@dscho One thing I just realized I don't understand -- in development I still see |
Even in development, it should now be |
Got it, made the CSS tweaks. |
@jvns It seems it's no longer deployed to gh-pages on your fork. But that's no problem, I did run it locally. For me these changes are ready to merge.
Yes. Makes sense to me. One nice addition would be to have clickable headlines, or a permalink icon next to it (like on the man pages). But that's not a change I consider blocking before this PR can be merged. @dscho Shall we merge then? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I think current version is mergable!
Someone on Mastodon suggested it would be nice to have a cheat sheet on the Git website, so I thought I'd put together a prototype to see if it's of interest, perhaps for a future "Learn" section of the site. You can see it in action here: Git cheat sheet
There are definitely lots of Git cheat sheets out there already (for example from github and from ndpsoftware), but it feels like it would be nice to have one that's lower tech and not GitHub branded.
The content and styling both definitely need work -- right now it's basically an import of this cheat sheet, which has some of my personal Git idiosyncracies in it (like insisting on using
HEAD^^^^^^
instead ofHEAD~5
🙈).I got a bit carried away writing handwritten SVG Git graphs, and I'm not sure they'll display in all browsers as is. Here's what they're meant to look like. I think I'll figure out a better solution than the handwritten SVGs, maybe graphviz.