本文内容来自我fork 并翻译的GitHub repo Git-Cheat-Sheet,若是内容有误或有新内容补充,欢迎你们给我发issue。javascript
Git cheat sheet 让你不用再去记全部的git命令。java
欢迎贡献内容、修正语法错误,也欢迎添加你母语版本的Git cheat sheet。linux
$ git config --list复制代码
$ git config --local --list复制代码
$ git config --global --list复制代码
$ git config --system --list复制代码
$ git config --global user.name “[firstname lastname]”复制代码
$ git config --global user.email “[valid-email]”复制代码
$ git config --global color.ui auto复制代码
$ git config --global core.editor vi复制代码
<repo>/.git/config复制代码
~/.gitconfig复制代码
/etc/gitconfig复制代码
# 经过 SSH
$ git clone ssh://user@domain.com/repo.git
#经过 HTTP
$ git clone http://domain.com/user/repo.git复制代码
$ git init复制代码
$ git status复制代码
$ git diff复制代码
$ git add .复制代码
$ git add -p <file>复制代码
$ git commit -a复制代码
$ git commit复制代码
$ git commit -m 'message here'复制代码
git commit --date="`date --date='n day ago'`" -am "Commit Message"复制代码
请勿修改已发布的提交记录!git
$ git commit --amend复制代码
GIT_COMMITTER_DATE="date" git commit --amend复制代码
git commit --amend --date="date"复制代码
git stash
git checkout branch2
git stash pop复制代码
git stash apply复制代码
git stash drop复制代码
$ git grep "Hello"复制代码
$ git grep "Hello" v2.5复制代码
$ git log复制代码
$ git log --oneline复制代码
$ git log --author="username"复制代码
$ git log -p <file>复制代码
$ git log --oneline <origin/master>..<remote/master> --left-right复制代码
$ git blame <file>复制代码
$ git reflog show复制代码
$ git reflog delete复制代码
$ git branch复制代码
$ git branch -r复制代码
$ git checkout <branch>复制代码
$ git checkout -b <branch>复制代码
$ git branch <new-branch>复制代码
$ git branch --track <new-branch> <remote-branch>复制代码
$ git branch -d <branch>复制代码
将会丢失未合并的修改!github
$ git branch -D <branch>复制代码
$ git tag <tag-name>复制代码
$ git tag -a <tag-name>复制代码
$ git remote -v复制代码
$ git remote show <remote>复制代码
$ git remote add <remote> <url>复制代码
$ git fetch <remote>复制代码
$ git remote pull <remote> <url>复制代码
$ git pull origin master复制代码
git pull --rebase <remote> <branch>复制代码
$ git push remote <remote> <branch>复制代码
$ git push <remote> :<branch> (since Git v1.5.0)
# or
git push <remote> --delete <branch> (since Git v1.7.0)复制代码
$ git push --tags复制代码
$ git merge <branch>复制代码
请勿重置已发布的提交!windows
$ git rebase <branch>复制代码
$ git rebase --abort复制代码
$ git rebase --continue复制代码
$ git mergetool复制代码
已解决冲突
:$ git add <resolved-file>
$ git rm <resolved-file>复制代码
$ git rebase -i <commit-just-before-first>复制代码
把上面的内容替换为下面的内容:缓存
原内容:bash
pick <commit_id>
pick <commit_id2>
pick <commit_id3>复制代码
替换为:服务器
pick <commit_id>
squash <commit_id2>
squash <commit_id3>复制代码
$ git reset --hard HEAD复制代码
git add
):$ git reset HEAD复制代码
$ git checkout HEAD <file>复制代码
$ git revert <commit>复制代码
$ git reset --hard <commit>复制代码
git reset --hard <remote/branch> e.g., upstream/master, origin/my-feature复制代码
$ git reset <commit>复制代码
$ git reset --keep <commit>复制代码
.gitignore
文件前错误提交的文件:$ git rm -r --cached .
$ git add .
$ git commit -m "remove xyz file"复制代码
$ brew install git-flow复制代码
$ port install git-flow复制代码
$ apt-get install git-flow复制代码
安装 git-flow, 你须要 wget 和 util-linux。app
$ wget -q -O - --no-check-certificate https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | bash复制代码
git flow init复制代码
下面操做建立了一个新的feature分支,并切换到该分支
git flow feature start MYFEATURE复制代码
完成开发新特性。这个动做执行下面的操做:
git flow feature finish MYFEATURE复制代码
你是否合做开发一项新特性?
发布新特性分支到远程服务器,因此,其它用户也可使用这分支。
git flow feature publish MYFEATURE复制代码
取得其它用户发布的新特性分支。
git flow feature pull origin MYFEATURE复制代码
经过下面命令追溯远端上的特性
git flow feature track MYFEATURE复制代码
git flow release start RELEASE [BASE]复制代码
建立 release 分支以后当即发布容许其它用户向这个 release 分支提交内容是个明智的作法。命令十分相似发布新特性:
git flow release publish RELEASE复制代码
(你能够经过git flow release track RELEASE
命令追溯远端的 release 版本)
完成 release 版本是一个大 git 分支操做。它执行下面几个动做:
git flow release finish RELEASE复制代码
不要忘记使用git push --tags
将tags推送到远端
紧急修复来自这样的需求:生产环境的版本处于一个不预期状态,须要当即修正。有多是须要修正 master 分支上某个 TAG 标记的生产版本。
像其它 git flow 命令同样, 紧急修复分支开始自:
$ git flow hotfix start VERSION [BASENAME]复制代码
VERSION 参数标记着修正版本。你能够从 [BASENAME]开始,
[BASENAME]`为finish release时填写的版本号
当完成紧急修复分支,代码归并回 develop 和 master 分支。相应地,master 分支打上修正版本的 TAG。
git flow hotfix finish VERSION复制代码