TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Git Cheat Sheet

182 pointsby akras14over 8 years ago

13 comments

dispose13432over 8 years ago
I think that while Git would be great as a library, as a front-facing program it&#x27;s UX could do an improvement:<p>A good UX is simple things should be simple, but complicated things should be possible, but now look at the following &quot;basic&quot; git workflow:<p>1. Add. I want git to track this file. Yes, sometimes I need to add certain lines, files, etc. Keep git add, commit, and push. But have a &quot;git update&quot; or something for beginners (and for 99% of use)<p>2. History - How can I go through a file to see its history? &quot;git show REV&quot;? What if I want a wikipedia style history? What if I want to go through the history of a file? There should be something like &quot;git history main.c&quot;<p>3. Undelete file - This is fairly common, yet, the command is<p>git checkout $(git rev-list -n 1 HEAD -- &quot;$file&quot;)^ -- &quot;$file&quot;<p>A command like git undelete $file would probably make life easier.<p>I haven&#x27;t gotten to the more complex workflow, and I definitely agree that git is a great revision system, but UX improvements can help<p>--- EDIT,<p>Mandatory xkcd<p><a href="https:&#x2F;&#x2F;xkcd.com&#x2F;1597&#x2F;" rel="nofollow">https:&#x2F;&#x2F;xkcd.com&#x2F;1597&#x2F;</a>
评论 #13179523 未加载
评论 #13179922 未加载
评论 #13178601 未加载
评论 #13178608 未加载
评论 #13179395 未加载
评论 #13179873 未加载
评论 #13181741 未加载
PaulJuliusover 8 years ago
I&#x27;m going to describe a small issue I&#x27;ve been having with Git that I&#x27;ve tried Googling for in the past but have never found a solution.<p>I use a custom `git log` alias that prints out a nicely colored commit graph.<p><pre><code> [alias] lg = log --graph --abbrev-commit --decorate --date=relative --format=format:&#x27;%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)&#x27; --all -n 15 </code></pre> The issue is that this includes everyone else&#x27;s branches that have been pushed to origin. I only want to see the history for local branches. (I guess I&#x27;d also want to be able to see origin&#x2F;master, but I recognize that there&#x27;s nothing distinguishing that from the other branches on origin I don&#x27;t want to see.)<p>I think the issue is that I run `git pull --prune` to get rid of any remote branches that have been deleted. I usually do this after I pull master, so I think I should just be running `git pull origin master --prune` as a single command.
评论 #13179936 未加载
NumberSixover 8 years ago
A version control system should be simple. Engineers should be able to focus on getting things to work&#x2F;done, not battling with a complicated, confusing version control system.<p>Most engineers should be performing two operations&#x2F;two command s the vast majority of the time:<p>check-in &lt;latest change&gt; check-out &lt;latest version&gt; or &lt;last good version&gt;<p>If a file is new, check-in should ask you if you want to add it to the project.<p>That should be it.<p>The proliferation of tutorials, cheat sheets, books, front end user interfaces like SourceTree for Git is a symptom of a problem.<p>KISS (Keep It Simple Stupid)
评论 #13179058 未加载
评论 #13183187 未加载
评论 #13179882 未加载
评论 #13179013 未加载
评论 #13179029 未加载
评论 #13179121 未加载
评论 #13179098 未加载
pbh101over 8 years ago
I always give this interactive cheatsheet [1] to git newbies to help them conceptualize the state transfer.<p>[1] <a href="http:&#x2F;&#x2F;ndpsoftware.com&#x2F;git-cheatsheet.html" rel="nofollow">http:&#x2F;&#x2F;ndpsoftware.com&#x2F;git-cheatsheet.html</a>
AceJohnny2over 8 years ago
My favourite remains Zack Rusin&#x27;s, from 9 years ago. The state graph was pretty useful as I was learning:<p><a href="http:&#x2F;&#x2F;zrusin.blogspot.com&#x2F;2007&#x2F;09&#x2F;git-cheat-sheet.html" rel="nofollow">http:&#x2F;&#x2F;zrusin.blogspot.com&#x2F;2007&#x2F;09&#x2F;git-cheat-sheet.html</a>
adhipover 8 years ago
Better One<p><a href="https:&#x2F;&#x2F;services.github.com&#x2F;on-demand&#x2F;downloads&#x2F;github-git-cheat-sheet.pdf" rel="nofollow">https:&#x2F;&#x2F;services.github.com&#x2F;on-demand&#x2F;downloads&#x2F;github-git-c...</a>
akavelover 8 years ago
My more intermediate-level cheat sheet: <a href="https:&#x2F;&#x2F;gingkoapp.com&#x2F;git-notes" rel="nofollow">https:&#x2F;&#x2F;gingkoapp.com&#x2F;git-notes</a>
yranadiveover 8 years ago
Not as organized as the above two, but having being able to access it from the commandline beats anything:<p>[1] Client: <a href="https:&#x2F;&#x2F;github.com&#x2F;evidanary&#x2F;grepg-python" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;evidanary&#x2F;grepg-python</a> [2] Cheat Sheet: <a href="https:&#x2F;&#x2F;greppage.com&#x2F;evidanary&#x2F;5" rel="nofollow">https:&#x2F;&#x2F;greppage.com&#x2F;evidanary&#x2F;5</a>
antmanover 8 years ago
At this point we need a Git Cheatheets Cheatsheet.
mplewisover 8 years ago
I&#x27;m also maintaining a small Git cheat sheet. It&#x27;s my personal list of stuff that I always find useful but can never remember how to type.<p>Let me know if you find it useful!<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;mplewis&#x2F;a7563c7cb589048a071b" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;mplewis&#x2F;a7563c7cb589048a071b</a>
Kiroover 8 years ago
&gt; # Unstage pending changes, and reset files to pre-commit state. If<p>If what?
Kiroover 8 years ago
git diff --staged should be in there. I always accidentally add stuff I&#x27;ve had the chance to look at the diff. Then this command comes in handy.
guard-of-terraover 8 years ago
Don&#x27;t like how it is based around merges. Cherry-pick workflow is so much simpler and provides clean history. &quot;No merges&quot; was the policy in every project I worked.