2009-11-22

Mini Reference for Git




This is a memo for Git commands.


*** config ***
- set user name and contact info
git config --global user.name "User Name"
git config --global user.email "name@domain.com"

- display current settings
git config --list

- turn on coloring mode
git config --global color.ui "auto"

- set an alias for a command
git config --global alias.<alias-name> "<native-command-name>"



*** mode ***
- Git with GUI
git gui

- display whole history using GUI
gitk

- display diff using GUI
git mergetool



*** command ***
- initialize and reinitialize .git
git init

- add git repository
git add <filename>
git add -i (Interact Mode)
git add -p (Patch Mode in Interact Mode)

- commit with a message
git commit -m "message"
git commit -C HEAD -a --amend (Amend previous commit by using same log message)

- revert commits
git revert -n <commit ID>
-> Do revert in time order to avoid waste troubles.

- reset change log by changing files
git reset --hard HEAD

- see the working tree from Git
git status

- change working branch
git checkout <destinated branch>
git checkout -b <new branch> <existing branch> (checkout with making new branch)

- make a branch
git branch <new branch> <based branch>
git branch <new branch> <based tag-name>
git branch -a (show all branches)
git branch -d <delete branch>
git branch -m ("mv" command for branches)
git branch -M ("mv" command for branches in rewriting mode)

- merge a branch
git checkout <master branch>
-> git merge <slave branch>
-> git merge --squash <slave branch> (Compressed Commit)
-> git cherry-pick <commit ID> (Cherry Pick)
-> git cherry-pick -n <commit ID> (put a commit into staging area)
--> Do not put "-m" option when committing because it already has a message.

- track back to previous situation
git reset --hard HEAD^ (Maybe you need to replace with "\^")

- put a tag on the current revision of branch
git tag <tag-name> <branch-name>

- fetch a change of branch and put it in front of another branch
git rebase <branch-name>
git rebase -i <commit ID> (It helps to change committing order)

- make a archive for release
git archive --format=tar --prefix=<dir-name> <tag-name> | gzip > <archive-name>.tar.gz
git archive --format=zip --prefix=<dir-name> <tag-name> | <zip-name>.zip

- read user manual
git help <command>

- see commit logs
git log
git log -<num> (Show some of logs in time order)
git log --pretty=oneline (Show each commit in 1 line)
git log -p (Display all differences between revisions)
git log <commit ID>
git log --since="<num> hours"
git log --before="today" | ="2009-11-22" | "yesterday"
git log <older commit ID>..<later commit ID>
git log <older commit ID>..HEAD{^} (from some commit to latest)
-> Windows may need double quotations.
git log HEAD~<num>..HEAD
git log -C -C -p (Display detailed info in each commit)

- display differences between corresponded files if existing
git diff
git diff --cached (Differences between Not Commited and Current files)
git diff HEAD (Display all differences in current branch)
git diff <commit ID>
git diff --stat <tag> (Display stats info between resources)

- Display who writes which codes
git blame <filename>
git blame -L <start>,<end> <filename>
git blame -L <start>,+|-<num> <filename>
git blame -M <filename> (look for same lines in a file)
git blame -C -C copy.txt (look for same lines between files)

- "mv" in Git
git mv <filename> <new filename>

*** others/memo ***
- Git cannot trace empty folders because they have no contents.
-> To avoid this, most people create a ".<filename>" file with meta contents.

- Git does not have to use "cp" command because it already copies when tracking.

- To ignore buffer files, add "a pattern name" into .git/info/exclude or .gitignore

0 件のコメント: