mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-19 03:25:44 +00:00
Merge pull request #92 from terminalforlife/master
New Examples & `sysctl` File + Wording & Formatting Improvements
This commit is contained in:
commit
167657879b
157
sheets/git
157
sheets/git
@ -1,46 +1,45 @@
|
||||
# To set your identity:
|
||||
# Set your identity.
|
||||
git config --global user.name "John Doe"
|
||||
git config --global user.email johndoe@example.com
|
||||
|
||||
# To set your editor:
|
||||
# Set your editor.
|
||||
git config --global core.editor emacs
|
||||
|
||||
# To enable color:
|
||||
# Enable color support for commands like `git diff`. Disable with `never` or
|
||||
# partially disable -- unless otherwise applied -- with `false`.
|
||||
git config --global color.ui true
|
||||
|
||||
# To stage all changes for commit:
|
||||
git add --all
|
||||
# Stage all changes for commit.
|
||||
git add [--all|-A]
|
||||
|
||||
# To stash changes locally, this will keep the changes in a separate changelist
|
||||
# called stash and the working directory is cleaned. You can apply changes
|
||||
# from the stash anytime
|
||||
# Stash changes locally. This will keep the changes in a separate changelist, -
|
||||
# called 'stash', and the working directory is cleaned. You can apply changes
|
||||
# from the stash at any time.
|
||||
git stash
|
||||
|
||||
# To stash changes with a message
|
||||
# Stash changes with a message.
|
||||
git stash save "message"
|
||||
|
||||
# To list all the stashed changes
|
||||
# List all the stashed changes.
|
||||
git stash list
|
||||
|
||||
# To apply the most recent change and remove the stash from the stash list
|
||||
# Apply the most recent change and remove the stash from the stash list.
|
||||
git stash pop
|
||||
|
||||
# To apply any stash from the list of stashes. This does not remove the stash
|
||||
# from the stash list
|
||||
# Apply stash from the stash list, but does not remove the stash from the list.
|
||||
git stash apply stash@{6}
|
||||
|
||||
# To commit staged changes
|
||||
# Commit staged changes.
|
||||
git commit -m "Your commit message"
|
||||
|
||||
# To edit previous commit message
|
||||
# Edit previous commit message.
|
||||
git commit --amend
|
||||
|
||||
# Git commit in the past
|
||||
# Commit in the past. Newer versions of Git allow `--date="2 days ago"` usage.
|
||||
git commit --date="`date --date='2 day ago'`"
|
||||
git commit --date="Jun 13 18:30:25 IST 2015"
|
||||
# more recent versions of Git also support --date="2 days ago" directly
|
||||
|
||||
# To change the date of an existing commit
|
||||
# Change the date of an existing commit.
|
||||
git filter-branch --env-filter \
|
||||
'if [ $GIT_COMMIT = 119f9ecf58069b265ab22f1f97d2b648faf932e0 ]
|
||||
then
|
||||
@ -48,144 +47,142 @@ git filter-branch --env-filter \
|
||||
export GIT_COMMITTER_DATE="Sat May 19 01:01:01 2007 -0700"
|
||||
fi'
|
||||
|
||||
# To removed staged and working directory changes
|
||||
# Remove staged and working directory changes.
|
||||
git reset --hard
|
||||
|
||||
# To go 2 commits back
|
||||
# Go 2 commits back.
|
||||
git reset --hard HEAD~2
|
||||
|
||||
# To remove untracked files
|
||||
# Remove untracked files.
|
||||
git clean -f -d
|
||||
|
||||
# To remove untracked and ignored files
|
||||
# Remove untracked and ignored files.
|
||||
git clean -f -d -x
|
||||
|
||||
# To push to the tracked master branch:
|
||||
# Push to the tracked master branch.
|
||||
git push origin master
|
||||
|
||||
# To push to a specified repository:
|
||||
git push git@github.com:username/project.git
|
||||
# Push to a specified repository.
|
||||
git push git@github.com:[USER_NAME]/[REPO_NAME].git
|
||||
|
||||
# To delete the branch "branch_name"
|
||||
git branch -D branch_name
|
||||
# Delete the branch "branch_name".
|
||||
git branch -D [BRANCH]
|
||||
|
||||
# To make an existing branch track a remote branch
|
||||
# Make an existing branch track a remote branch.
|
||||
git branch -u upstream/foo
|
||||
|
||||
# To list all local and remote branches
|
||||
# List all local and remote branches.
|
||||
git branch -a
|
||||
|
||||
# To see who committed which line in a file
|
||||
git blame filename
|
||||
# See who committed which line in a file.
|
||||
git blame [FILE]
|
||||
|
||||
# To sync a fork with the master repo:
|
||||
git remote add upstream git@github.com:name/repo.git # Set a new repo
|
||||
git remote -v # Confirm new remote repo
|
||||
git fetch upstream # Get branches
|
||||
git branch -va # List local - remote branches
|
||||
git checkout master # Checkout local master branch
|
||||
git checkout -b new_branch # Create and checkout a new branch
|
||||
git merge upstream/master # Merge remote into local repo
|
||||
git show 83fb499 # Show what a commit did.
|
||||
git show 83fb499:path/fo/file.ext # Shows the file as it appeared at 83fb499.
|
||||
git diff branch_1 branch_2 # Check difference between branches
|
||||
git log # Show all the commits
|
||||
git status # Show the changes from last commit
|
||||
# Sync a fork with the master repo.
|
||||
git remote add upstream git@github.com:name/repo.git # <-- Set a new repo.
|
||||
git remote -v # <-- Confirm new remote repo.
|
||||
git fetch upstream # <-- Get branches.
|
||||
git branch -va # <-- List local - remote branches.
|
||||
git checkout master # <-- Checkout local master branch.
|
||||
git checkout -b new_branch # <-- Create and checkout a new branch.
|
||||
git merge upstream/master # <-- Merge remote into local repo.
|
||||
git show 83fb499 # <-- Show what a commit did.
|
||||
git show 83fb499:path/fo/file.ext # <-- Show the file as it was in 83fb499.
|
||||
git diff branch_1 branch_2 # <-- Check difference between branches.
|
||||
git log # <-- Show all of the commits.
|
||||
git status # <-- Show the changes from the last commit.
|
||||
|
||||
# Commit history of a set of files
|
||||
# Display the commit history of a set of files.
|
||||
git log --pretty=email --patch-with-stat --reverse --full-index -- Admin\*.py > Sripts.patch
|
||||
|
||||
# Import commits from another repo
|
||||
# Import commits from another repo.
|
||||
git --git-dir=../some_other_repo/.git format-patch -k -1 --stdout <commit SHA> | git am -3 -k
|
||||
|
||||
# View commits that will be pushed
|
||||
# View commits which would be pushed.
|
||||
git log @{u}..
|
||||
|
||||
# View changes that are new on a feature branch
|
||||
# View changes which are new on a feature branch.
|
||||
git log -p feature --not master
|
||||
git diff master...feature
|
||||
|
||||
# Interactive rebase for the last 7 commits
|
||||
# Interactive rebase for the last 7 commits.
|
||||
git rebase -i @~7
|
||||
|
||||
# Diff files WITHOUT considering them a part of git
|
||||
# This can be used to diff files that are not in a git repo!
|
||||
# Show changes to files WITHOUT considering them a part of git. This can be
|
||||
# used to diff files which are not part of a git repo!
|
||||
git diff --no-index path/to/file/A path/to/file/B
|
||||
|
||||
# To pull changes while overwriting any local commits
|
||||
# Pull changes, while overwriting any local commits.
|
||||
git fetch --all
|
||||
git reset --hard origin/master
|
||||
|
||||
# Update all your submodules
|
||||
# Update all submodules.
|
||||
git submodule update --init --recursive
|
||||
|
||||
# Perform a shallow clone to only get latest commits
|
||||
# (helps save data when cloning large repos)
|
||||
# Perform a shallow clone, to only get the latest commits, which helps to save
|
||||
# data (good for limited data connections) when cloning large repos.
|
||||
git clone --depth 1 <remote-url>
|
||||
|
||||
# To unshallow a clone
|
||||
# Unshallow a clone.
|
||||
git pull --unshallow
|
||||
|
||||
# Create a bare branch (one that has no commits on it)
|
||||
# Create a bare branch; without any commits.
|
||||
git checkout --orphan branch_name
|
||||
|
||||
# Checkout a new branch from a different starting point
|
||||
# Checkout a new branch from a different starting point.
|
||||
git checkout -b master upstream/master
|
||||
|
||||
# Reset local branch to upstream branch and then checkout it
|
||||
# Reset local branch to upstream branch, then checkout it.
|
||||
git checkout -B master upstream/master
|
||||
|
||||
# Remove all stale branches (ones that have been deleted on remote)
|
||||
# So if you have a lot of useless branches, delete them on Github and then run this
|
||||
# Remove all stale branches; ones that have been deleted on remote. So if you
|
||||
# have a lot of useless branches, delete them on GitHub and then run this.
|
||||
git remote prune origin
|
||||
|
||||
# The following can be used to prune all remotes at once
|
||||
# Prune all remotes at once.
|
||||
git remote prune $(git remote | tr '\n' ' ')
|
||||
|
||||
# Revisions can also be identified with :/text
|
||||
# So, this will show the first commit that has "cool" in their message body
|
||||
# Revisions can also be identified with `:/text`. So, this will show the first
|
||||
# commit that has the string "cool" in its message body.
|
||||
git show :/cool
|
||||
|
||||
# Undo parts of last commit in a specific file
|
||||
# Undo parts of the last commit in a specific file.
|
||||
git checkout -p HEAD^ -- /path/to/file
|
||||
|
||||
# Revert a commit and keep the history of the reverted change as a separate revert commit
|
||||
# Revert a commit, but keep the history of the event as a separate commit.
|
||||
git revert <commit SHA>
|
||||
|
||||
# Pick a commit from a branch to current branch. This is different than merge as
|
||||
# this just applies a single commit from a branch to current branch
|
||||
git cherry-pick <commit SHA1>
|
||||
# Apply only the changes made within a given commit. This is different to the
|
||||
# `merge` command, as it would otherwise apply all commits from a branch.
|
||||
git cherry-pick [HASH]
|
||||
|
||||
# Undo last commit
|
||||
# If you want to nuke commit C and never see it again
|
||||
# Undo last commit. If you want to nuke commit C to never see it again:
|
||||
# (F)
|
||||
# A-B-C
|
||||
# ↑
|
||||
# master
|
||||
git reset --hard HEAD~1
|
||||
|
||||
# Undo last commit
|
||||
# If you want to undo the commit but keep your changes
|
||||
# Undo last commit. If you want to undo the commit, but keep your changes:
|
||||
# (F)
|
||||
# A-B-C
|
||||
# ↑
|
||||
# master
|
||||
git reset HEAD~1
|
||||
|
||||
# list files changed in ${commit_id}
|
||||
git diff-tree --no-commit-id --name-only -r ${commit_id}
|
||||
# List files changed in a given commit.
|
||||
git diff-tree --no-commit-id --name-only -r [HASH]
|
||||
|
||||
# list files changed in ${commit_id}, porcelain way, meant to be user facing
|
||||
# Porcelain-ly List files changed in a given commit; user-facing approach.
|
||||
git show --pretty="" --name-only bd61ad98
|
||||
|
||||
# See everything you have done, across branches, in a glance,
|
||||
# then go to the place right before you broke everything
|
||||
# See everything you have done, across branches, in a glance, then go to the
|
||||
# place right before you broke everything.
|
||||
git reflog
|
||||
git reset HEAD@{hash}
|
||||
|
||||
# To move your most recent commit from one branch and stage it on TARGET branch
|
||||
# Move your most recent commit from one branch, to stage it on [BRANCH].
|
||||
git reset HEAD~ --soft
|
||||
git stash
|
||||
git checkout TARGET
|
||||
git checkout [BRANCH]
|
||||
git stash pop
|
||||
git add .
|
||||
|
@ -28,3 +28,6 @@ perl -p -i'.old' -e 's/find/replace/g' filename
|
||||
# learn perl: /perl/:learn
|
||||
# perl one-liners: /perl/1line
|
||||
# search in pages: /perl/~keyword
|
||||
|
||||
# Perl method of listing out the environment variables, sans values.
|
||||
perl -e 'print("$_\n") foreach keys(%ENV)'
|
||||
|
56
sheets/ssh
56
sheets/ssh
@ -1,58 +1,60 @@
|
||||
# ssh
|
||||
# access a remote host via SSH
|
||||
|
||||
# To ssh via pem file (which normally needs 0600 permissions):
|
||||
# SSH in via PEM file, which normally needs 0600 permissions.
|
||||
ssh -i /path/to/file.pem user@example.com
|
||||
|
||||
# To connect on an non-standard port:
|
||||
# Connect through a non-standard port. It's recommended not to use the default
|
||||
# port of 22, as it is so often targeted, due to it being so commonplace.
|
||||
ssh -p 2222 user@example.com
|
||||
|
||||
# To connect and forward the authentication agent
|
||||
# Connect and forward the authentication agent.
|
||||
ssh -A user@example.com
|
||||
|
||||
# To execute a command on a remote server:
|
||||
# Execute a command on a remote server.
|
||||
ssh -t user@example.com 'the-remote-command'
|
||||
|
||||
# To tunnel an x session over SSH:
|
||||
# Tunnel an X session over SSH, via X11 Forwarding.
|
||||
ssh -X user@example.com
|
||||
|
||||
# Redirect traffic with a tunnel between local host (port 8080) and a remote
|
||||
# host (remote.example.com:5000) through a proxy (personal.server.com):
|
||||
# host (remote.example.com:5000) through a proxy (personal.server.com).
|
||||
ssh -f -L 8080:remote.example.com:5000 user@personal.server.com -N
|
||||
|
||||
# To launch a specific x application over SSH:
|
||||
# Launch a specific X application over SSH.
|
||||
ssh -X -t user@example.com 'chromium-browser'
|
||||
|
||||
# To create a SOCKS proxy on localhost and port 9999
|
||||
# Create a SOCKS proxy on localhost and port 9999.
|
||||
ssh -D 9999 user@example.com
|
||||
|
||||
# -X use an xsession, -C compress data, "-c blowfish" use the encryption blowfish
|
||||
ssh user@example.com -C -c blowfish -X
|
||||
# Connect to server, but allow for X11 forwarding, while also using GZip
|
||||
# compression (can be much faster; YMMV), and using the `blowfish` encryption.
|
||||
# For more information, see: http://unix.stackexchange.com/q/12755/44856
|
||||
ssh -XCc blowfish user@example.com
|
||||
|
||||
# For more information, see:
|
||||
# http://unix.stackexchange.com/q/12755/44856
|
||||
# Copy files and directories, via SSH, from remote host to the current working
|
||||
# directory, with GZip compression. An option for when `rsync` isn't available.
|
||||
#
|
||||
# This works by creating (not temporary!) a remote Tar archive, then piping its
|
||||
# output to a local Tar process, which then extracts it to STDOUT.
|
||||
ssh user@example.com 'tar -C /var/www/Shared/ zcf - asset1 asset2' | tar zxf -
|
||||
|
||||
# Copy files and folders through ssh from remote host to pwd with tar.gz compression
|
||||
# when there is no rsync command available
|
||||
ssh user@example.com "cd /var/www/Shared/; tar zcf - asset1 asset2" | tar zxf -
|
||||
|
||||
# explicitly specify a key for connection
|
||||
# (if you have Too many authentication failures for *username*)
|
||||
# Explicitly specify a key for connection. Useful if you have too many
|
||||
# authentication failures for a given username.
|
||||
ssh -i some_id_rsa -o IdentitiesOnly=yes them@there:/path/
|
||||
|
||||
# switch off pubkey authentication
|
||||
# Temporarily disable `pubkey` authentication for this instance.
|
||||
ssh -o PubkeyAuthentication=no username@hostname.com
|
||||
|
||||
# Mount folder/filesystem through SSH
|
||||
# Install SSHFS from https://github.com/libfuse/sshfs
|
||||
# Will allow you to mount a folder securely over a network.
|
||||
# Mount a remote directory or filesystem, through SSH, to a local mountpoint.
|
||||
# Install SSHFS from: https://github.com/libfuse/sshfs
|
||||
sshfs name@server:/path/to/folder /path/to/mount/point
|
||||
|
||||
# Emacs can read file through SSH
|
||||
# EMACS can read files through SSH.
|
||||
# Doc: http://www.gnu.org/software/emacs/manual/html_node/emacs/Remote-Files.html
|
||||
emacs /ssh:name@server:/path/to/file
|
||||
|
||||
# Get help on SSH escape sequences
|
||||
# Useful for terminating unresponsive sessions
|
||||
# The default escape character is ~ (tilde), escapes are only recognized immediately after newline
|
||||
$ [Enter]~?
|
||||
# Get help for SSH escape sequences. Useful for terminating unresponsive
|
||||
# sessions. The default escape character is ~ (tilde), escapes are only
|
||||
# recognized immediately after a newline.
|
||||
$ <Enter>~?
|
||||
|
12
sheets/sysctl
Normal file
12
sheets/sysctl
Normal file
@ -0,0 +1,12 @@
|
||||
# List all kernel keys (parameters) and their values.
|
||||
sysctl [--all|-a]
|
||||
# As above, but show only specified keys and their values.
|
||||
sysctl [KEY_1 [KEY_2] ...]
|
||||
|
||||
# As above, but instead output only the values.
|
||||
sysctl [--values|-n] [KEY_1 [KEY_2] ...]
|
||||
# Not nearly as useful, but alternatively, output only the key names.
|
||||
sysctl [--names|-N] [KEY_1 [KEY_2] ...]
|
||||
|
||||
# Assign one or more kernel keys a new value; usually requires root access.
|
||||
sysctl [KEY_1=VALUE_1 [KEY_2=VALUE_2] ...]
|
17
sheets/tee
17
sheets/tee
@ -1,16 +1,15 @@
|
||||
# To tee stdout to a file:
|
||||
# Display `ls` output to the user, but also write it to the given file.
|
||||
ls | tee outfile.txt
|
||||
|
||||
# To tee stdout and append to a file:
|
||||
# As above, but amend the data; previous file's data remains in-tact.
|
||||
ls | tee -a outfile.txt
|
||||
|
||||
# tee would take the output of the first command in the pipeline and copy it
|
||||
# to standard output (the terminal) while also making copies of it in the files one, two and three:
|
||||
somecommand | tee one two three
|
||||
# Pipe the standard output of a given command into `tee`, which then displays
|
||||
# it to the user and sending the data to files `one`, `two`, and `three`.
|
||||
[COMMAND] | tee one two three
|
||||
|
||||
# write 3 to /proc/sys/vm/drop_caches (with root rights)
|
||||
# Workaround to output data to a file, with root privileges.
|
||||
echo 3 | sudo tee /proc/sys/vm/drop_caches
|
||||
|
||||
# in Vim:
|
||||
# The structure :w !cmd means "write the current buffer piped through command".
|
||||
# Pipe the current Vim buffer to a shell process, which in this case is `tee`.
|
||||
# This is especially useful as a shortcut added to `.vimrc` or similar.
|
||||
:w !sudo tee %
|
||||
|
Loading…
Reference in New Issue
Block a user