-
-
Save defbobo/28c35662df3b8741cd2f19cd13804c7f to your computer and use it in GitHub Desktop.
The sheet originaly forked from aleksey-bykov/git-cheat-list.md
-
specifying revisions: http://schacon.github.io/git/git-rev-parse.html#_specifying_revisions
-
list of all affected files both tracked/untracked (for automation)
git status --porcelain
-
name of the current banch and nothing else (for automation)
git rev-parse --abbrev-ref HEAD
-
all commits that your branch have that are not yet in master
git log master..<HERE_COMES_YOUR_BRANCH_NAME>
-
setting up a character used for comments
git config core.commentchar <HERE_COMES_YOUR_COMMENT_CHAR>
-
fixing
fatal: Could not parse object
after unsuccessful revertgit revert --quit
-
view diff with inline changes (by lines)
git diff --word-diff=plain master
-
view diff of changes in a single line file (per char)
git diff --word-diff-regex=. master
-
view quick stat of a diff
git diff --shortstat master git diff --numstat master git diff --dirstat master
-
undo last just made commit
git reset HEAD~
-
list last 20 hashes in reverse
git log --format="%p..%h %cd %<(17)%an %s" --date=format:"%a %m/%d %H:%M" --reverse -n 20
-
list commits between dates
git log --format="%p..%h %cd %<(17)%an %s" --date=format:"%a %m/%d %H:%M" --reverse --after=2016-11-09T00:00:00-05:00 --before=2016-11-10T00:00:00-05:00
-
try a new output for diffing
git diff --compaction-heuristic ... --color-words ...
-
enable more thorough comparison
git config --global diff.algorithm patience
-
restoring a file from a certain commit relative to the latest
git checkout HEAD~<NUMBER> -- <RELATIVE_PATH_TO_FILE>
-
restoring a file from a certain commit relative to the given commit
git checkout <COMMIT_HASH>~<NUMBER> -- <RELATIVE_PATH_TO_FILE>
-
restoring a file from a certain commit
git checkout <COMMIT_HASH> -- <RELATIVE_PATH_TO_FILE>
-
creating a diff file from unstaged changes for a specific folder
git diff -- <RELATIVE_PATH_TO_FOLDER> changes.diff
-
applying a diff file
- go to the root directory of your repository
- run:
git apply changes.diff
-
show differences between last commit and currrent changes:
git difftool -d
-
referring to:
- last commits
... HEAD~1 ...
- last 3 commits
... HEAD~3 ...
- last commits
-
show the history of changes of a file
git log -p -- ./Scripts/Libs/select2.js
-
ignoring whitespaces
git rebase --ignore-whitespace <BRANCH_NAME>
-
pulling for fast-forward only (eliminating a chance for unintended merging)
git pull --ff-only
-
list of all tags
git fetch git tag -l
-
archive a branch using tags
git tag <TAG_NAME> <BRANCH_NAME> git push origin --tags
you can delete your branch now
-
get a tagged branch
git checkout -b <BRANCH_NAME> <TAG_NAME>
-
list of all branches that haven't been merged to master
git branch --no-merge master
-
enable more elaborate diff algorithm by default
git config --global diff.algorithm histogram
-
list of all developers
git shortlog -s -n -e
-
display graph of branches
git log --decorate --graph --all --date=relative
or
git log --decorate --graph --all --oneline
-
remembering the password
git config --global credential.helper store git fetch
the first command tells git to remember the credentials that you are going to provide for the second command
-
path to the global config
C:\Users\Bykov\.gitconfig
-
example of a global config
[user] email = ***** name = Aleksey Bykov password = ***** [merge] tool = p4merge [mergetool "p4merge"] cmd = p4merge.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\" path = \"C:/Program Files/Perforce\" trustExitCode = false [push] default = simple [diff] tool = meld compactionHeuristic = true [difftool "p4merge"] cmd = p4merge.exe \"$LOCAL\" \"$REMOTE\" path = C:/Program Files/Perforce/p4merge.exe [difftool "meld"] cmd = \"C:/Program Files (x86)/Meld/Meld.exe\" \"$LOCAL\" \"$REMOTE\" path = C:/Program Files (x86)/Meld/Meld.exe
-
viewing differences between current and other branch
git difftool -d BRANCH_NAME
-
viewing differences between current and stash
git difftool -d stash
-
viewing differences between several commits in a diff tool
git difftool -d HEAD@{2}...HEAD@{0}
-
view all global settings
git config --global -l
-
delete tag
git tag -d my-tag git push origin :refs/tags/my-tag
-
pushing tags
git push --tags
-
checking the history of a file or a folder
git log -- <FILE_OR_FOLDER>
-
disabling the scroller
git --no-pager <...>
-
who pushed last which branch
git for-each-ref --format="%(committerdate) %09 %(refname) %09 %(authorname)"
-
deleting remote branch
git push origin :<BRANCH_NAME>
-
deleting remote branch localy
git branch -r -D <BRANCH_NAME>
or to sync with the remote
git fetch --all --prune
-
deleting local branch
git branch -d <BRANCH_NAME>
-
list actual remote branchs
git ls-remote --heads origin
-
list all remote (fetched) branches
git branch -r
-
list all local branches
git branch -l
-
find to which branch a given commit belongs
git branch --contains <COMMIT>
-
updating from a forked repository
git remote add upstream https://github.com/Microsoft/TypeScript.git git fetch upstream git rebase upstream/master
# Original forked from bsweger/useful_pandas_snippets.py | |
import pandas as pd | |
import numpy as np | |
from sqlalchemy import create_engine | |
engine = create_engine('mysql://root:xxx@127.0.0.1/lj?charset=utf8') | |
house = pd.read_sql_table('example', engine) | |
house_dd = pd.read_sql_query('select url, location, area, layout, size, buildtime, price, created from example group by url having count(url) > 1', engine) | |
def strip(text): | |
try: | |
return text.strip() | |
except AttributeError: | |
return text | |
def make_int(text): | |
return int(text.strip('" ')) | |
df = pd.DataFrame() | |
df1 = pd.read_csv('example.csv', sep=';') | |
df2 = pd.read_csv('new.csv', dtype=str, index_col=False, | |
usecols=['deal_num', 'acount', 'number'], | |
converters = {'deal_num' : strip, | |
'acount' : strip, | |
'number' : make_int}) | |
# List unique values in a DataFrame column | |
pd.unique(df.column_name.ravel()) | |
# Convert Series datatype to numeric, getting rid of any non-numeric values | |
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True) | |
# Grab DataFrame rows where column has certain values | |
valuelist = ['value1', 'value2', 'value3'] | |
df = df[df.column.isin(valuelist)] | |
# Grab DataFrame rows where column doesn't have certain values | |
value_list = ['value1', 'value2', 'value3'] | |
df = df[~df.column.isin(value_list)] | |
# Delete column from DataFrame | |
del df['column'] | |
# Select from DataFrame using criteria from multiple columns | |
# (use `|` instead of `&` to do an OR) | |
newdf = df[(df['column_one'] > 2004) & (df['column_two'] == 9)] | |
# Rename several DataFrame columns | |
df = df.rename(columns={ | |
'col1 old name': 'col1 new name', | |
'col2 old name': 'col2 new name', | |
'col3 old name': 'col3 new name', | |
}) | |
# Lower-case all DataFrame column names | |
df.columns = map(str.lower, df.columns) | |
# Even more fancy DataFrame column re-naming | |
# lower-case all DataFrame column names (for example) | |
df.rename(columns=lambda x: x.split('.')[-1], inplace=True) | |
# Loop through rows in a DataFrame | |
# (if you must) | |
for index, row in df.iterrows(): | |
print(index, row['some column']) | |
# Much faster way to loop through DataFrame rows | |
# if you can work with tuples | |
# (h/t hughamacmullaniv) | |
for row in df.itertuples(): | |
print(row) | |
# Next few examples show how to work with text data in Pandas. | |
# Full list of .str functions: http://pandas.pydata.org/pandas-docs/stable/text.html | |
# Slice values in a DataFrame column (aka Series) | |
df.column.str[0:2] | |
# Lower-case everything in a DataFrame column | |
df.column_name = df.column_name.str.lower() | |
# Get length of data in a DataFrame column | |
df.column_name.str.len() | |
# Sort dataframe by multiple columns | |
df = df.sort(['col1', 'col2', 'col3'], ascending=[1, 1, 0]) | |
# Get top n for each group of columns in a sorted dataframe | |
# (make sure dataframe is sorted first) | |
top5 = df.groupby(['groupingcol1', 'groupingcol2']).head(5) | |
# Grab DataFrame rows where specific column is null/notnull | |
newdf = df[df['column'].isnull()] | |
# Select from DataFrame using multiple keys of a hierarchical index | |
df.xs(('index level 1 value', 'index level 2 value'), level=('level 1', 'level 2')) | |
# Change all NaNs to None (useful before | |
# loading to a db) | |
df = df.where((pd.notnull(df)), None) | |
# More pre-db insert cleanup...make a pass through the dataframe, stripping whitespace | |
# from strings and changing any empty values to None | |
# (not especially recommended but including here b/c I had to do this in real life one time) | |
df = df.applymap(lambda x: str(x).strip() if len(str(x).strip()) else None) | |
# Get quick count of rows in a DataFrame | |
len(df.index) | |
# Pivot data (with flexibility about what what | |
# becomes a column and what stays a row). | |
# Syntax works on Pandas >= .14 | |
pd.pivot_table( | |
df,values='cell_value', | |
index=['col1', 'col2', 'col3'], #these stay as columns; will fail silently if any of these cols have null values | |
columns=['col4']) #data values in this column become their own column | |
# Change data type of DataFrame column | |
df.column_name = df.column_name.astype(np.int64) | |
# Get rid of non-numeric values throughout a DataFrame: | |
for col in refunds.columns.values: | |
refunds[col] = refunds[col].replace('[^0-9]+.-', '', regex=True) | |
# Set DataFrame column values based on other column values (h/t: @mlevkov) | |
df.loc[(df['column1'] == some_value) & (df['column2'] == some_other_value), ['column_to_change']] = new_value | |
# Clean up missing values in multiple DataFrame columns | |
df = df.fillna({ | |
'col1': 'missing', | |
'col2': '99.999', | |
'col3': '999', | |
'col4': 'missing', | |
'col5': 'missing', | |
'col6': '99' | |
}) | |
# Concatenate two DataFrame columns into a new, single column | |
# (useful when dealing with composite keys, for example) | |
df['newcol'] = df['col1'].map(str) + df['col2'].map(str) | |
# Doing calculations with DataFrame columns that have missing values | |
# In example below, swap in 0 for df['col1'] cells that contain null | |
df['new_col'] = np.where(pd.isnull(df['col1']),0,df['col1']) + df['col2'] | |
# Split delimited values in a DataFrame column into two new columns | |
df['new_col1'], df['new_col2'] = zip(*df['original_col'].apply(lambda x: x.split(': ', 1))) | |
# Collapse hierarchical column indexes | |
df.columns = df.columns.get_level_values(0) | |
# Convert Django queryset to DataFrame | |
qs = DjangoModelName.objects.all() | |
q = qs.values() | |
df = pd.DataFrame.from_records(q) | |
# Create a DataFrame from a Python dictionary | |
df = pd.DataFrame(list(a_dictionary.items()), columns = ['column1', 'column2']) | |
# Get a report of all duplicate records in a dataframe, based on specific columns | |
dupes = df[df.duplicated(['col1', 'col2', 'col3'], keep=False)] | |
# Set up formatting so larger numbers aren't displayed in scientific notation (h/t @thecapacity) | |
pd.set_option('display.float_format', lambda x: '%.3f' % x) |
vagrant init {boxname} 初始化
vagrant status 查看虚拟机运行状态
vagrant up 启动虚拟机
vagrant halt 关闭虚拟化开发环境
vagrant reload 修改配置文件后,重启虚拟化开发环境
vagrant port 查看端口映射
vagrant box add {target} --name box {boxname}
vagrant box list 查看当前可用的虚拟化开发环境
vagrant box remove boxname 删除指定的box环境
vagrant global-status 查看环境
vagrant destroy 销毁虚拟机
vagrant package 当前正在运行的VirtualBox虚拟环境打包成一个可重复使用的box
vagrant init phusion/ubuntu-14.04-amd64
vagrant up
vagrant ssh
vagrant halt
1、打包虚拟机
vagrant package
2、当前目录就会生成package.box,之后新建虚拟机则可使用这个box。
vagrant box add my_box ~/package.box
vagrant init my_box
vagrant up