一定要先测试命令的效果后,再用于工作环境中,以防造成不能弥补的后果!到时候别拿着砍刀来找我
所有的命令都在git version 2.7.4(Apple Git-66)下测试通过
统一概念:
工作区:改动(增删文件和内容)
暂存区:输入命令:git add 改动的文件名,此次改动就放到了 ‘暂存区’
本地仓库(简称:本地):输入命令:git commit 此次修改的描述,此次改动就放到了 ’本地仓库’,每个 commit,我叫它为一个 ‘版本’。
远程仓库(简称:远程):输入命令:git push 远程仓库,此次改动就放到了 ‘远程仓库’(GitHub 等)
commit-id:输出命令:git log,最上面那行 commit xxxxxx,后面的字符串就是 commit-id
如果喜欢这个项目,欢迎 Star、提交 Pr、反馈问题[3]
git help -g
The common Git guides are:
attributes Defining attributes per path
cli Git command-line interface and conventions
core-tutorial A Git core tutorial for developers
cvs-migration Git for CVS users
diffcore Tweaking diff output
everyday A useful minimum set of commands for Everyday Git
glossary A Git Glossary
hooks Hooks used by Git
ignore Specifies intentionally untracked files to ignore
modules Defining submodule properties
namespaces Git namespaces
repository-layout Git Repository Layout
revisions Specifying revisions and ranges for Git
tutorial A tutorial introduction to Git
tutorial-2 A tutorial introduction to Git: part two
workflows An overview of recommended workflows with Git
'git help -a' and 'git help -g' list available subcommands and some concept guides. See 'git help
git fetch --all && git reset --hard origin/master
git update-ref -d HEAD
git diff
git diff <commit-id> <commit-id>
git diff --cached
git diff HEAD
git checkout -
git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d
git branch -vv
git branch -u origin/mybranch
git push origin/mybranch -u
git branch -r
git branch -a
git checkout -b <branch-name>
git checkout -b <branch-name> origin/<branch-name>
git branch -d <local-branchname>
git push origin --delete <remote-branchname>
git push origin :<remote-branchname>
git branch -m <new-branch-name>
git tag
git describe --tags --abbrev=0
git tag -ln
git tag <version-number>
$ git tag -a <version-number> -m "v1.0 发布(描述)" <commit-id>
git push origin <local-version-number>
git push origin --tags
git tag -d <tag-name>
git push origin :refs/tags/<tag-name>
git checkout -b branch_name tag_name
git checkout <file-name>
git checkout .
git rev-list -n 1 HEAD --
git checkout
git revert <commit-id>
git reset <commit-id> #默认就是-mixed参数。
git reset –mixed HEAD^ #回退至上个版本,它将重置HEAD到另外一个commit,并且重置暂存区以便和HEAD相匹配,但是也到此为止。工作区不会被更改。
git reset –soft HEAD~3 #回退至三个版本之前,只回退了commit的信息,暂存区和工作区与回退之前保持一致。如果还要提交,直接commit即可
git reset –hard <commit-id> #彻底回退到指定commit-id的状态,暂存区和工作区也会变为指定commit-id版本的内容
git commit --amend
git log
git blame <file-name>
git reflog
git commit --amend --author='Author Name
git remote set-url origin <URL>
git remote add origin <remote-url>
git remote
git whatchanged --since='2 weeks ago'
git checkout <branch-name> && git cherry-pick <commit-id>
git config --global alias.<handle>
比如:git status 改成 git st,这样可以简化命令
git config --global alias.st status
git stash
git stash -u
git stash list
git stash apply <stash@{n}>
git stash pop
git stash clear
git checkout <stash@{n}> -- <file-path>
git ls-files -t
git ls-files --others
git ls-files --others -i --exclude-standard
clean 后,删除的文件无法找回
不会影响 tracked 的文件的改动,只会删除 untracked 的文件
git clean <file-name> -f
git clean <directory-name> -df
git log --pretty=oneline --graph --decorate --all
git bundle create
git clone repo.bundle <repo-dir> -b <branch-name>
git rebase --autostash
git fetch origin pull/<id>/head:<branch-name>
git diff --word-diff
git clean -X -f
git config --local --list(当前目录)
git config --global --list(全局)
git status --ignored
git log Branch1 ^Branch2
git log --show-signature
git config --global --unset <entry-name>
git checkout --orphan <branch-name>
git show <branch-name>:<file-name>
git clone -b <branch-name> --single-branch https://github.com/user/repo.git
git update-index --assume-unchanged path/to/file
git update-index --no-assume-unchanged path/to/file
git config core.fileMode false
git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/
git log --all --grep='
git reset <file-name>
git push -f <remote-name> <branch-name>
标题行:必填,描述主要修改类型和内容
主题内容:描述为什么修改,做了什么样的修改,以及开发的思路等等
页脚注释:放 Breaking Changes 或 Closed Issues
type:commit 的类型
feat:新特性
fix:修改问题
refactor:代码重构
docs:文档修改
style:代码格式修改,注意不是 css 修改
test:测试用例修改
chore:其他修改,比如构建流程,依赖管理
scope:commit 影响的范围,比如:route,component,utils,build……
subject:commit 的概述
body:commit 具体修改内容,可以分为多行
footer:一些备注,通常是 BREAKING CHANGE 或修复的 bug 的链接
npm install -g commitizen cz-conventional-changelog
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
https://github.com/git-tips/tips
http://rogerdudler.github.io/git-guide/index.zh.html
https://github.com/521xueweihan/git-tips/issues
http://sg552.iteye.com/blog/1300713#bc2367928
https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137602359178794d966923e5c4134bc8bf98dfb03aea3000
https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines
https://github.com/commitizen/cz-cli