+---------+ +----------+ +--------+ +------+
|untracked| |unmodified| |modified| |staged|
+----+----+ +----------+ +----+---+ +---+--+
| |edit | |
|add +-----------> |
+-------------> |stage |
| | +--------->
| remove| | |
<-------------+ | |
| | | commit|
| <---------------------+
| | | |
- initializing repo:
$ git init
- cloning existing repo:
$ git clone <repo url>
files may be tracked -> in last snapshot
{
* unmodified
* modified
* staged
}
untracked -> everything else
- tracking new files:
$ git add <filename>
- staging modified files:
$ git add <filename>
- viewing changes:
$ git status
- compare working directory and staging area:
$ git diff
- compare staging area and last commit:
$ git diff --staged
$ git diff --cached
- committing changes:
$ git commit
$ git commit -m "<commit message>"
- skipping the staging area:
$ git commit -a
- removing files:
$ git rm <filename>
- remove file and keeo copy in working directory:
$ git rm --cached <filename>
- moving files:
$ git mv <src> <dest>
- viewing history:
$ git log
- show diffs:
$ git log -p
- limit output to 2 entries:
$ git log -2
- stats for each commit:
$ git log --stat
$ git log --pretty={short,full,fuller,oneline}
$ git log --graph
- format fields:
%H commit hash
%h abbreviated commit hash
%T tree hash
%t abbreviated tree hash
%P parent hashes
%p abbreviated parent hashes
%s subject
%an author name
%ae author email
%ad author date
%ar author date, relative
%cn committer name
%ce committer email
%cd committer date
%cr committer date, relative
| |
-p | show patch introduced with each commit |
--stat | show statistics for files modified in each commit |
--shortstat | display only the changed/insertions/deletions in each commit |
--name-only | show list of files modified after commit information |
--name-status | show list of files affected with A/M/D info |
--abbrev-commit | show only first few characters of SHA1 |
--relative-date | display date in relative format instead of full date |
--graph | display ascii graph of the branch/merge history beside the log output |
--pretty | show commits in alternative format |
-<n> | show last commits |
--since | limit commits to those made after a date |
--after | limit commits to those made after a date |
--until | limit commits to those made before a date |
--before | limit commits to those made before a date |
--author | show commits in which the author entry matches |
--committer | |
--grep | |
-- <path> | |