Working Directory | Staging area | .git repository |
---|---|---|
<= | = checkout= | =< |
stage >= | => | |
commit >= | => |
Per-project: .git/config
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
$ git config --global core.editor vim
$ git config --list
$ git init
$ git clone https://github.com/libgit2/libgit2 [mygitlib]
Untracked | Unmodified | Modified | Staged |
---|---|---|---|
add the file >= | == | == | => |
edit the file >= | => | ||
stage the file >= | => | ||
<= | =< remove the file | ||
<= | == | =< commit the file |
$ git status
$ git add .
$ git add README.md
$ git add *.c
$ git add modified.file
git status -s
*.a
: no a-files...!lib.a
: ...except for lib.a/TODO
: ignore TODO in the current directory, but not in other directoriesbuild/
: ignore all files in the build directorydoc/*.txt
: ignore txt files in the doc directorydoc/**/*.pdf
: ignore txt files in doc and all its subdirs$ git diff
$ git diff --staged
or $ git diff --cached
$ git commit
or $ got commit -m "my message"
$ git commit -a -m "my message"
git add .
followed by $ git commit -m "my message"
$ git rm
removes files from the staging area and removes it from the drive.$ rm
the change will be recorded. You must still type $ git rm
to remove it from the stage area before committing.$ git rm --cached
$ git mv a b
$ mv a b
followed by $ git rm a && git add b
$ git log
$ git log -p -N
$ git log --stat
use --pretty=keyword option. Keywords are
format
$ git log --pretty=format:"%h - %an, %ar : %s"
%H, %h: Commit hash, abbrev. commit hash
%T, %t: Tree hash, abbrev. tree hash
%P, %p: Parent hash, abbrev. parent hash
%an, %ae: Author name, author email
%ad, %ar: Author date, author date, relative
%cn, %ce: Committer name, committer email
%cd, %cr: Committer date, committer date, relative
%s: Subject
Show graph: git log --pretty=format:"%h %s" --graph
other options: