This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
git [2017/01/19 12:25] frank created |
git [2017/08/31 15:23] (current) frank |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| === Contribute to github === | === Contribute to github === | ||
| - configure local git<code> | - configure local git<code> | ||
| - | $ git config --global user.name "frdeng" | + | $ git config --list |
| - | $ git config --global user.email "frank.deng@oracle.com" | + | $ git config --global user.name "San Zhang" |
| + | $ git config --global user.email "san.zhang@example.com" | ||
| + | // global config file is ~/.gitconfig | ||
| </code> | </code> | ||
| - fork a repo on github.com | - fork a repo on github.com | ||
| Line 11: | Line 13: | ||
| - add upstream to your repo<code> | - add upstream to your repo<code> | ||
| $ git remote add upstream https://github.com/boxcutter/oraclelinux.git | $ git remote add upstream https://github.com/boxcutter/oraclelinux.git | ||
| + | $ git remote -v | ||
| </code> | </code> | ||
| - fetch upstream<code> | - fetch upstream<code> | ||
| Line 32: | Line 35: | ||
| </code> | </code> | ||
| - create new pull request on github.com | - create new pull request on github.com | ||
| + | - Once PR is accepted, the fix is merged to upstream, then sync up with upstream. Fetch upstream, and rebase upstream, then push to own forked repo(origin><code> | ||
| + | $ git checkout master | ||
| + | $ git fetch upstream | ||
| + | $ git rebase upstream/master | ||
| + | $ git push origin master | ||
| + | </code> | ||
| + | === git configuration === | ||
| + | <code> | ||
| + | $ git config --list | ||
| + | $ git config [--global] -e | ||
| + | $ git config [--global] user.name "San Zhang" | ||
| + | $ git config [--global] user.email "san.zhang@example.com" | ||
| + | // global config file is ~/.gitconfig | ||
| + | |||
| + | </code> | ||
| + | |||
| + | === branch and tag === | ||
| + | <code> | ||
| + | # list tags | ||
| + | $ git tag -n | ||
| + | # list local branches | ||
| + | $ git branch | ||
| + | # list remote branches | ||
| + | $ git branch -r | ||
| + | # list local and remote branches | ||
| + | $ git branch -a | ||
| + | # create a new branch, but do not switch to the branch | ||
| + | $ git branch [branch] | ||
| + | # create a branch and switch to it | ||
| + | $ git checkout -b [branch] | ||
| + | # create a new branch and track remote branch | ||
| + | $ git branch --track [branch] [remote-branch] | ||
| + | $ git checkout -b [branch] --track [remote-branch] or git checkout -b [branch] [remote-branch] //tracking is by default | ||
| + | # track current branch to remote branch | ||
| + | $ git branch --set-upstream-to [remote-branch] | ||
| + | # track a branch to remote branch | ||
| + | $ git branch --set-upstream-to [remote-branch] [branch] | ||
| + | # merge a branch to current branch | ||
| + | $ git merge [branch] | ||
| + | # pick a commit and merge to current branch | ||
| + | $ git cherry-pick [commit] | ||
| + | # delete a branch | ||
| + | $ git branch -d [branch] | ||
| + | # delete a remote branch | ||
| + | $ git push origin --delete [branch] or git branch -dr [remote/branch] | ||
| + | |||
| + | # list tags | ||
| + | $ git tag | ||
| + | # create a tag at current commit | ||
| + | $ git tag [tag] | ||
| + | # create a tag at specific commit | ||
| + | $ git tag [tag] [commit] | ||
| + | # delete local branch | ||
| + | $ git tag -d [tag] | ||
| + | # push specific tag | ||
| + | $ git push [remote] [tag] | ||
| + | # push all tags | ||
| + | $ git push [remote] --tags | ||
| + | # create a new branch from a tag | ||
| + | $ git checkout -b [branch] [tag] | ||
| + | </code> | ||
| + | |||
| + | === add/remove file === | ||
| + | <code> | ||
| + | $ git add [file1] [file2] ... [-p] | ||
| + | $ git add . //add all files to cache | ||
| + | $ git rm [file1] [file2] ... | ||
| + | $ git rm --cached [file1] //remove from cache but remain in working area | ||
| + | $ git mv [filename] [new filename] | ||
| + | </code> | ||
| + | |||
| + | === commit === | ||
| + | <code> | ||
| + | $ git commit -m "message" | ||
| + | $ git commit [file1] [file2] ... -m "message" | ||
| + | $ git commit -a //commit all | ||
| + | $ git commit -v //show diff info | ||
| + | # show one specific commit | ||
| + | $ git show [commit] | ||
| + | # show the affected files in the commit | ||
| + | $ git show --name-only [commit] | ||
| + | # display the file content at the cmmit | ||
| + | $ git show [commit]:[filename] | ||
| + | |||
| + | </code> | ||
| + | |||
| + | === get diff === | ||
| + | <code> | ||
| + | # display diff between working area and cache | ||
| + | $ git diff | ||
| + | # display diff between cache and last commit | ||
| + | $ git diff --cached [file] | ||
| + | # display diff between work and latest commit | ||
| + | $ git diff HEAD | ||
| + | # display diff between two branches | ||
| + | $ git diff [branch1]...[branch2] | ||
| + | # display diff on specific directory between two branches | ||
| + | $ git diff release-3.1..master -- version/ | ||
| + | diff --git a/version/version.go b/version/version.go | ||
| + | index 6cb3c08..9134ceb 100644 | ||
| + | --- a/version/version.go | ||
| + | +++ b/version/version.go | ||
| + | @@ -26,7 +26,7 @@ import ( | ||
| + | var ( | ||
| + | // MinClusterVersion is the min cluster version this etcd binary is compatible with. | ||
| + | MinClusterVersion = "3.0.0" | ||
| + | - Version = "3.1.0+git" | ||
| + | + Version = "3.2.0+git" | ||
| + | APIVersion = "unknown" | ||
| + | |||
| + | // Git SHA Value will be set during build | ||
| + | |||
| + | </code> | ||
| + | |||
| + | === get information === | ||
| + | <code> | ||
| + | # display changes | ||
| + | $ git status | ||
| + | # display current branch version history | ||
| + | $ git log | ||
| + | # display current branch commit history including affected files | ||
| + | $ git log --stat | ||
| + | # search from log by keyword | ||
| + | $ git log -S [keyword] | ||
| + | # display all changes after some specific commit, show each commit in one line | ||
| + | $ git log [tag ] HEAD --pretty=format:%s | ||
| + | # display all changes after some specific commit, and search keyword | ||
| + | $ git log [tag] HEAD --grep [keyword] | ||
| + | # display one specific file history, including file name | ||
| + | $ git log --follow [file] or git whatchanged [file] | ||
| + | # display each diff of a file | ||
| + | $ git log -p [file] | ||
| + | # display last 5 commits | ||
| + | $ git log -5 --pretty --oneline | ||
| + | # display all users that have commits, sort by # of commits | ||
| + | $ git shortlog -sn | ||
| + | # display the specific file when and who has changed | ||
| + | $ git blame [file] | ||
| + | |||
| + | # reference log | ||
| + | $ git reflog | ||
| + | </code> | ||
| + | |||
| + | === remote === | ||
| + | <code> | ||
| + | # download all changes | ||
| + | $ git fetch [remote] | ||
| + | # show remote | ||
| + | $ git remote -v | ||
| + | # add a new remote git repo and name it | ||
| + | $ git remote add [shortname] [url] | ||
| + | # pull all remote changes and merge to local branch | ||
| + | $ git pull [remote] [branch] | ||
| + | # upload local branch to remote | ||
| + | $ git push [remote] [branch] | ||
| + | # force to push current branch to remote | ||
| + | $ git push [remote] --force | ||
| + | # push all branches to remote | ||
| + | $ git push [remote] --all | ||
| + | </code> | ||