Files
git add .
— adds everything to index
git commit -am "Comment"
— makes commit of all changes with specific comment. (New files are NOT auto added!)
git checkout -- path/to/file
— undoes uncommitted changes to specific file
git checkout -- .
— same as above for full repository
git diff-tree --no-commit-id --name-only -r abcdef
— lists names of files for a specific commit
git log -p filename
— lists changes history for specific filename (provide .
filename to see changes for whole project)
git diff
— lists unstaged changes
git diff --cached
— lists staged changes
git reset path/to/file
— removes file from “Changes to be committed”
git clean -f
— removes all unstaged files
git checkout changes -- /php/code.php
— retrieves /php/code.php file from changes branch
Branches
git checkout -b new-branch
— creates new branch with name “new-branch” and switches to it
git merge master
— merges into current branch from branch with name “master”. Optional --no-commit
can be passed in order not to commit after merge (In case you need some more changes for example)
git log new-branch..master
— lists all commits on branch “master” which are not in branch “new-branch”
git branch -d branch-name
— deletes branch
Remotes
git remote add another git@localhost:/git/repo.git
— creates new another remote
git remote rm origin
— removes origin remote
git remote rename origin new-origin
— renames origin remote to new-origin
git remote set-url origin git@localhost:/git/repo.git
— changes url associated with origin remote
Stashes
git stash list
— list all stashes
git stash
— stashes uncommitted changes
git stash save "Stash message"
— stashes uncommitted changes with specific message
git stash save --keep-index "Stash not indexed"
— same as above, but will only stash not added to index changes (Changes not staged for commit)
git stash pop
— applies stashed changes (And removes stash state from stash list)
git stash apply
— same as above, but doesn’t remove stash state from stash list
git stash clear
— clear all stash states from stash list
git stash drop stash@\{0\}
— deletes stash with stash@{0} name (From git stash list
). Don’t forget to escape curly brackets!
git stash show -p stash@\{0\}
— describes stash changes (Output similar to git diff
)
Config
git config --list
— list all config values
git config config-key value
— sets “value” as value for config key “config-key”
git config --unset config-key
— deletes config key “config-key” and its value
git --edit
— edit config as text document
--global
option can be used for all config commands in order to access global config (Not current repository only)
годное фуфло! Одобряю