Simple git reference
Everyday git
12 cool things you can do with GitHub
ADD git.txt write-up here :)
| `git -h` | show a short overview of the <command> syntax |
| `git help ` | open a manual of the <command> (such as [git status](https://git-scm.com/docs/git-status)) |
| `` | limit a command to one commit |
| `git log` | show commit logs |
| `-3` | 3 last commits |
| `-z` | separate comments with NULs instead of new lines and add highlighted `^@` before the commit |
| `-b` | ignore changes in amount of whitespace |
| `-p` `` | show commits with differences (hit Q to quit) |
| `-Stekst` | commits where string `tekst` was added or removed (eg to find a reference to a specific function) |
| ⋅`-L` `,:` | shows changes in from lines `` to ``. opt search several diff line scopes or even files. opt use regex. |
| `--pretty=oneline` | show one commit per line eg `51dee0585e1a2b601c1347cab79d89761d32b1e7 Initial commit` |
| `--pretty=format:` `"%"` | changes the log output to formats other than the default [see % options](https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History#pretty_format); eg `3 days ago` |
| `--pretty=` `short` / `medium` | show `commit, author, commit message` / previous + `date` |
| `--date=format:` `"%H:%M %d.%m.%y"` | output `16:10 06.12.16` [see % options](http://stackoverflow.com/a/34778736); used together w `--pretty=format:"%ad"` |
| `--name-status` | list commmited files (w A/M/D : added/modified/deleted info) |
| `--name-only` | adds names of changed files |
| `--reverse` | list commits in reversed order (latest last) |
| ⋅`--since=` `2.weeks` / `2016-12-01` | commits of the last 2 weeks / since 2016-12-01 |
| ⋅`--until=` `2.weeks` / `2016-12-01` | commits until 2 weeks ago / until 2016-12-01 |
| `--stat` | show abbreviated stats about commits |
| `--shortstat` | also shows the nr of changes and changed files in addition to `git log` output without options |
| `--graph` | show commits as an ASCII tree |
| `--color=never` | show output in white only |
| `--abbrev-commit` | use short version of SHA-1 checksum (commit id) |
| `--relative-date` | use relative, not full date (eg `2 weeks ago`) |
| `--grep` `'text_in_commit_msg'` ⋅`` | show commits that include the string in the message. Optionally limit search with files/dirs that were changed during that commit. |
| !`--all-match` | when using multiple `--grep`-s, limit commits output to ones that match all `--grep` rules |
| !`--invert-grep` | limit output to `--grep`-ed commits that *DON'T* match grep |
| !`-i` | case insensitive |
| ⋅`-- ` `` | show commits with changes related to `myfolder` NB! note the space between `--` and folder name; Needs to be the **last option**. |
| ⋅`--diff-filter=` `A` / `C` / `D` / `M` / `R` / `T` / `U` | show only files that are Added, Copied, Deleted, Modified, Renamed, Type changed, Unmerged |
| ⋅`--diff-filter=` `a` / `c` / `d` / `m` / `r` / `t` / `u` | EXclude such files |
| `--reflog` | list all reflogs as if they were separate commits |
| `--parents` / `--children` | also show parent / children commit ID |
Examples | |
| > `git log --follow --find-renames -z -p --` `` | show complete history of `` (including renames) |
| `gitk ` | open graphical UI to see changes to `` (file or folder) |
| `--follow` `` | follow filename past renames |
| `git show` `` | show changes of the last commit or specified `` |
| `git branch` | shows local branches |
| `-r` | shows remote branches |
| `-a` | shows all branches (remote and local) |
| `-d ` | deletes a branch (eg if already merged with master) |
| `-f -d ` | deletes a branch irrespective of its merged status |
| `git merge ` | merges branch into parent (eg master branch) |
| `git checkout` | switches to a branch local modifications to the files in the working tree are kept, so that they can be committed to the |
| `-b ` | create a new branch |
| `-B ` | create a new branch if it doesn’t exist or otherwise reset the branch |
| `-f` | `--force` switch to a branch while throwing away local changes |
| `git add` | add file contents to the index (stage files and changes) |
| `.` | tere |
| ⋅`-A` | add all |
| `git status` | tere |
| `git push` | tere |
| `origin master` | pushes to `master` branch on `origin` server (eg GitHub or Bitbucket) |
| `git pull --all` | tere |
| `git citool` | graphical alternative to git-commit |
| `git commit` | record changes to the repo |
| `-m` | pushes to `master` branch on `origin` server (eg GitHub or Bitbucket) |
| `-a` | automatically stage files that have been modified or deleted (new files are excluded) |
| ⋅`--dry-run` | obtain a summary of what is included in commit (wo actually committing) |
| `git rm` | tere |
| `git track` | switch branches or restore / update files in the working tree to match the version in the index or the specified tree |
| `` | tere |
| `git init` | create an empty Git repository or reinitialize an existing one. Safe to use on an existing repo |
| `` | tere |
| `git reset` | reset current HEAD to the specified state (default: remove all files/folders from staging area) |
| `` | unstage only ``. keep all changes. `path` |
| `--hard` | reset versioned files. delete unversioned STAGED files. keep unversioned unstaged files. |
| `--merge` | discard changes to staged files (both versioned and unversioned) |
| `git clean` | remove untracked files from the working tree |
| ⋅`-n` | don’t actually remove anything, just show what would be done. |
| ⋅`-f` | forces to remove the files if git conf var `clean.requireForce`==`true` |
| `-i` | show what would be done and clean files interactively. 'select by numbers' allows multiple or range deletions |
| `-X` | remove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files. |