This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
git [2017/08/29 12:44] frank |
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 "Frank Deng" | + | $ 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 40: | Line 42: | ||
</code> | </code> | ||
- | === get remote release branch === | + | === git configuration === |
<code> | <code> | ||
- | $ git branch --track remotes/origin/release-3.1 | + | $ 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> | </code> | ||
- | === get diff between branches === | + | === get diff === |
<code> | <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/ | $ git diff release-3.1..master -- version/ | ||
diff --git a/version/version.go b/version/version.go | diff --git a/version/version.go b/version/version.go | ||
Line 64: | Line 150: | ||
</code> | </code> | ||
- | === branch and tag === | + | === get information === |
- | * list tags<code> | + | <code> |
- | $ git tag -n | + | # display changes |
- | </code> | + | $ git status |
- | * list branches<code> | + | # display current branch version history |
- | $ git branch -a | + | $ git log |
- | </code> | + | # display current branch commit history including affected files |
- | * check out local branch from a tag<code> | + | $ git log --stat |
- | $ git checkout -b local_branch_name origin/remote_tag_name | + | # 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> | </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> |