Skip to content

Instantly share code, notes, and snippets.

@ausarenglish
Forked from jorgedfbranco/git cheat sheet
Created January 5, 2022 12:27
Show Gist options
  • Save ausarenglish/253c21299139e3524ace6daac1a419e1 to your computer and use it in GitHub Desktop.
Save ausarenglish/253c21299139e3524ace6daac1a419e1 to your computer and use it in GitHub Desktop.
History:
--all searches over the entire repository instead of only in the current branch
- git log --oneline (compressed, one line for commit)
- git log --grep <regex> (searches for commits with the given regex expression in their message)
- git log -Smysearchstring (searches for all the commits that contain any change for mysearchstring in this branch, that is, it looks at
files contents, not to commit messages.)
- git log --pretty=format:"%Cgreen%h %Cred%cn %Cblue%s"
  - git log --pretty=format:"%<|(20) %Cgreen%h %Cred%cn %Cblue%s" (with column)
-git log master..<feature> (gives us the history since our <feature> branch forked off from master!)
-git show HEAD@{2013-02-25}:./version.sbt <- shows the file as it was on 2013-02-25.
when using log, use the -g to look through the whole repo, not just the current branch. this includes dangling commits.
- git diff <commit>^! (shows the diff between <commit> and its parent)
git diff --staged/--cached (to --staged looks at the index/staging area)
Listing changes:
- git status -s (-s for short one liners for each file)
Cleaning the current directory:
- git clean -df (-d to include empty directories, -f to force any actual action to occur. --dry-run/-n may also be employed)
History rewriting:
- git reset <commit> (moves this branch's pointer to <commit>. leaves the files/modifications introduced by later commits on the
directory)
Stashing:
- git stash -u (-u includes untracked files)
- git stash --keep-index (only stash stuff in the index)
Merging:
- git merge --no-ff <commit> (no fast-forward)
Push:
- git push --all (pushes all the repos branches to the remote repository)
Remove remote branches
- git fetch --prune (updates the local remote branches to match the deletions from the remote repos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment