From 2db369175ff1d69bf6ace7e67a5bc47d3cf9f186 Mon Sep 17 00:00:00 2001 From: Brian Chen Date: Sun, 5 Oct 2014 19:00:28 +0800 Subject: [PATCH] Cheat sheet: make Git section much more extensive --- c/index.html | 74 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/c/index.html b/c/index.html index a968c10..ffd4f8d 100644 --- a/c/index.html +++ b/c/index.html @@ -26,10 +26,11 @@ a:link, a:visited {color: #ccc; text-shadow: white 1px 1px 1px;} a:hover {color: #0cc;} td {background-color: #333; border: 0;} - td.empty {background-color: #222;} + td.empty {background-color: #222; color: #444; } th {background-color: #666; font-weight: bold;} .cr, .crow td {background-color: #933;} .cg {background-color: #363;} + .cb {background-color: #336;} .padded td {padding: 5px;} .toggle {color: #0cc;} td.outside {background-color: #000;} @@ -688,13 +689,70 @@

Packages

Git

- - - - - - - + + + + + +
CommandDescription
[git checkout master]
git checkout (files)
Reset local unstaged changes
[]
git reset HEAD (files)
Make changes unstaged
git diffUnstaged vs staged
git diff --cachedStaged vs last commit
git diff HEADWorking (unstaged / staged) vs last commit
git ls-files | xargs wc -lCount lines...
Key
command, subcommand, flag etc.
file
commit / branch / tree-ish +
    +
  • HEAD = @ = thing pointing in repo
  • +
  • commit^ = commit~ = parent
  • +
  • mergecommit^2 = second parent
  • +
  • commit~2 = grandparent
  • +
+
remote (origin, upstream)
+

Remember there are five areas:

+ + + +
StashWorkspaceIndexLocal RepoUpstream
hide stuffactual files that non-git stuff manipulatestaging area, --cached etc.committed
HEAD points somewhere here
push, pull
+

The actual cheat sheet.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CommandSubcommands, flags, argumentsDescription
gitstatus
hist[alias]
    hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
(see git immersion)
addfiles
-u / --updateall modifications and deletions
-A / --allall additions, modifications, and deletions
commit
-a / --alllike add -u
--amend
branch[-r / -a]list (remote / all)
-d / -Dbranchdelete (safe / forceful)
newbranchnew branch (but not checked out; you probably want checkout -b)
oldbranch
checkoutmaster
-bbranchFirst make new branch
fileReset local unstaged changes
resetHEADfilesReset index = make changes unstaged
--softbranchReset HEAD
--hardHEADReset index and workspace = destroy changes
diff(Working = unstaged) vs staged
--cached / --stagedStaged vs last commit
HEADWorking vs last commit
HEAD^HEADChanges of last commit (easily generalized)
remotelist remotes
addupstreamgit://foo
push
upstreambranch
-u / --set-upstreamtrack branches
-f / --forceafter you screw up
mergebranchUse some other tree-ish to extend this one
rebasestemGraft branch and commits somewhere else
tip(tip will first get checked out)
-i / --interactiveHEAD~1337interactive rebase: rearrange, edit, squash commits... +
    +
  • pick: keep as is
  • +
  • edit: make changes (can add commits etc.)
  • +
  • reword: only change commit message
  • +
  • squash: absorb into previous commit + message
  • +
  • fixup: absorb into previous commit, delete this message
  • +
--continuewith interactive
reverttree-ishMake a commit that restores to this commit
ls-files| xargs wc -lCount lines...

Ascii