

$ 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/.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 init $ git status$ git diff$ git diff $ git add .$ git add -p $ git add $ git commit -a$ git commit$ git commit -m 'message here'$ git commit --date="`date --date='n day ago'`" -am "Commit Message"请勿修改已发布的提交记录!
$ git commit --amendGIT_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 -S 'keyword'$ git log -S 'keyword' --pickaxe-regex$ git log$ git log --oneline$ git log --author="username"$ git log -p $ git log --oneline .. --left-right$ git blame $ git reflog show $ git reflog delete将 Index.txt 重命名为 Index.html
$ git mv Index.txt Index.html$ git branch$ git branch -a$ git branch -r$ git checkout $ git checkout -- $ git checkout -b $ git checkout -$ git checkout -b $ git checkout -b $ git branch $ git branch --track $ git branch -d 将会丢失未合并的修改!
$ git branch -D $ git tag $ git tag -a $ git tag -am 'message here'$ git tag$ git tag -n$ git remote -v$ git remote show $ git remote add $ git remote rename $ git remote rm 注意:git remote rm 不会从服务器上删除远程仓库。它只是从本地仓库中删除远程文件及其引用。
$ git fetch $ git remote pull $ git pull origin mastergit pull --rebase $ git push remote $ git push : (since Git v1.5.0)或
$ git push --delete (since Git v1.7.0)$ git push --tags$ git merge $ git branch --merged请勿重置已发布的提交!
$ git rebase $ git rebase --abort$ git rebase --continue$ git config --global merge.tool meld$ git mergetool$ git add $ git rm $ git rebase -i 把下面的内容:
pick
pick
pick 替换为:
pick
squash
squash $ git reset --hard HEADgit add):$ git reset HEAD$ git checkout HEAD $ git revert $ git reset --hard git reset --hard e.g., upstream/master, origin/my-feature$ git reset $ git reset --keep .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。
$ wget -q -O - --no-check-certificate https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | bashgit flow init下面操作创建了一个基于 'develop' 的新特性分支,并切换到该分支。
git flow feature start MYFEATURE完成开发新特性。这个动作执行以下操作:
git flow feature finish MYFEATUREgit flow feature publish MYFEATURE获取由其它用户发布的新特性分支。
git flow feature pull origin MYFEATURE通过下面的命令追溯远程上的特性
git flow feature track MYFEATUREgit 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 将标签推送到远程。
热修复来自这样的需求:生产环境的版本处于非预期状态时需要立即采取行动。有可能是需要修复 master 分支上某个标记的生产版本。
像其它 git flow 命令一样,热修复分支开始自:
$ git flow hotfix start VERSION [BASENAME]VERSION 参数标记新的热修复发布名称。你还可以指定从哪个 [BASENAME] 开始,[BASENAME] 是完成 release 版本时填写的版本号。
当完成热修复,分支代码将被合并到 develop 和 master 分支。相应地,master 分支打上热修复版本的标签。
git flow hotfix finish VERSION
