CREATE
From existing data
|
1 2 3 4 |
cd ~/projects/myproject git init git add . |
From Existing repo
|
1 2 3 |
git clone ~/existing/repo ~/new/repo git clone you@host.org:dir/project.git |
12 Default protocol is ssh
Remove repository from existing local data
|
1 2 3 |
mkdir repo.git && cd repo.git git init --bare[--shared=group] |
UPDATE
Fetch latest changes from origin
|
1 2 |
get fetch |
12 this does not merge them
Pull latest changes from origin
|
1 2 |
git pull |
12 does a fetch followed by a merge
Apply a patch that someone sent you
|
1 2 |
git am -3 patch.mbox |
12 In case of conflict, resolve the conflict and
|
1 2 |
git am --resolve |
PUBLISH
Commit all local changes
|
1 2 |
git commit -a |
Prepare a patch for other developers
|
1 2 |
git format-patch origin |
Push changes to origin
|
1 2 |
git push [origin] [branch] |
Make a version of Milestone
|
1 2 |
git tag<Version_name> |
Branch
Switch to the BRANCH branch
|
1 2 |
git checkout <BRANCH> |
Merge branch B1 into branch B2
|
1 2 |
git checkout <new> <base> |
Delete a branch
|
1 2 |
git branch -d <branch> |
REVERT
Return to the last committed state
|
1 2 |
git checkout -f | git reset --hard |
12 you can not undo a hard reset
Revert the Last commit
|
1 2 |
git revert HEAD |
12 Create a new commit
Revert specific commit
|
1 2 |
git revert $id |
12 creates a new commit
Fix the last commit
|
1 2 |
git commit -a --amend |
12 after editing the broken files
Checkout the ID version of a file
|
1 2 |
git checkout <ID> <file> |
SHOW
Files changed in working directory
|
1 2 |
git status |
Changes to tracked files
|
1 2 |
git diff |
Changes between ID1 and ID2
|
1 2 |
git diff <ID1><ID2> |
Hisotry of changes
|
1 2 |
git log |
History of changes with the files changed
|
1 2 |
git whatchanged |
Who changed what and when in a file
|
1 2 |
git blame<file> |
A commit identified by ID
|
1 2 |
git show <ID> |
A specific file from a specific ID
|
1 2 |
git diff <ID>:<FILE> |
All local branches
|
1 2 |
git branch |
12 star "*" marks the current branch
Search for patterns
|
1 |
git grep <pattern>[path] |
master is the default development branch
origin is the default upstream repository
HEAD is the current branch
流程图:
