remote
列出远程仓库
git remote
git remote -v
git remote show origin
git remote add myClone https://github.com/Kuri-su/Portflow-Monitor.git
git remote rename origin ori
git remote rm origin
clone
可以使用各种专用协议 [ ssh:// | git:// | file:// | http:// ]
克隆仓库
git clone https://url.com/Kuri-su.git
git clone https://url.com/Kuri-su.git test
checkout
git checkout master
git checkout -b test2
git checkout -- readme.md
git checkout --track origin/dev
branch
创建分支
git branch test
git branch still-a-branch 38bb7da5e
git branch still-a-branch older-branch
查看分支
git branch
git branch -v
git branch -vv
git branch --merge
git branch --no-merged
git branch -a
git branch -r
切换跟踪的远程分支
git branch -u origin/serverfix
删除分支
git branch -d test
git branch -D test
tag
列出标签
git tag
git tag -l 'v1.8.5*'
贴上标签
git tag v1.4
git tag 1.4.7 e7b084 -m "alpha beta"
git tag -a v1.4 -m 'my version 1.4'
diff
git diff foo.txt
查看暂存区文件和HEAD的区别
git diff --staged
指定范围内比较
git diff 77d231f HEAD
git diff 77d231f^
git diff 77d231f 05bcfd1 - book/bisection/
log
显示提交差异和统计信息
git log -2
git log -p -2
git log --stat
简短 | 完整 的显示提交
git log
git log --pretty=online
git log --pretty=short
git log --pretty=full
git log --pretty=fuller
git log --pretty=format:"%h - %an, %ar : %s"
图形化显示 合并 | 提交 | 分支 历史
git log --stat
git log --graph
根据日期筛选提交
git log --after=2.weeks
git log --before="2017-10-15"
根据 作者 | 提交者 | 文件 筛选提交
git log --author kurisu
git log --committer kurisu
git log git.png
根据 关键字 筛选提交
git log --grep kurisu
git log -S function_name
查看从dev分支上还没有合并到master的那些提交(双点号)
git log master..dev
git log ^branchA branchB
git log branchA..branchB
git log branchA --not branchB
git log branchA branchB ^branchC
git log branchA branchB --not branchC
查看两个提交的非共有提交(三点号)
git log master...experiment
日志搜索
git log -S ZLIB_BUF_MAX --oneline
git log -G GitFlow --stat --oneline
git log -L :git_deflate_bound:zlib.c
显示提交修改了什么文件
git log --name-only
note
git log --abbrev-commit --oneline
git log --graph --oneline
rebase
请谨慎使用变基操作!
不要将任何已经推送到中央服务器中的提交包含在内,这样做会出现相同变更的不同版本,造成混乱
"如果你听取上述忠告,那就万事大吉。否则,同事会埋怨你,朋友和家人会鄙视你。"
git rebase master
改变历史
git rebase -i HEAD~3
底层指令 ( Plumbing ) ( undone )
cat-file
查看资源库对象的内容或类型和大小信息
git cat-file -p HEAD
对象的基本内容,包括SHA-1,父提交的SHA-1,提交者的信息和提交时间,提交备注信息
git cat-file -s HEAD
对象的大小
git cat-file -t HEAD
对象的类型
ls-tree
列出树对象的内容
git ls-tree -r HEAD
递归列出树对象的内容
ls-files
查看索引(也称为暂存区)的文件列表
git ls-files -s
输出更详细的信息,包括SHA-1等
git ls-files -d
delete files
git ls-files -m
modified files
hash-object ( undone )
write-tree ( undone )
update-index
git update-index --assume-unchanged foo.txt
git update-index --no-assume-unchanged foo.txt
git update-index --really-refresh
read-tree ( undone )
update-ref ( undone )
symbolic-ref ( undone )
verify-pack ( undone )
rev-parse
git rev-parse dev
filter-branch
git filter-branch --tree-filter 'rm -f .env passwords.txt' HEAD
git filter-branch --subdirectory-filter trunk HEAD
git filter-branch --commit-filter 'if ["$GIT_AUTHOR_EMAIL"="schacon@localhost"];then GIT_AUTHOR_NAME="Scott Chacon"; GIT_AUTHOR_EMAIL="schacon@example.com"; git commit-tree "$@";else git commit-tree "$@";fi HEAD'
reflog
git在你工作的同时,会在后台保存一份reflog,这是一份最近几个月你的HEAD和分支引用的日志
grep
git grep -n TODO
git grep --count TODO
git grep --break --heading -n -e '#define' --and \(-e LINK -e BUF_MAX \) v1.8.0
show
git show v1.4
git show 1c002d
git show 1c002d --name-only
stash
保存到储存栈
git stash [ save "message" ]
git stash -u
git stash --keep-index
从储存栈恢复
git stash pop
git stash pop stash@{2}
git stash apply
git stash apply stash@{2}
从储存栈删除
git stash drop
git stash drop stash@{2}
git stash clear
基于暂存创建一个分支
git stash branch testChange
储存未被跟踪的文件
git stash [-u|--include-untracked]
交互式的询问每一个文件是否需要缓存
git stash --patch
reset
git reset HEAD <file>
git reset --hard 39ea21a
取消工作区的合并!
git reset --merge
git reset --soft
git reset --mixed
git reset --hard
你可以使用reset来进行压缩提交,比如对现在这个二进制的git.xmind文件
先 git reset --soft b123456 git.xmind
然后git commit 即可
这样就不需要进行变基操作
status
查看工作目录状态
git status
git status [ -s | --short ]
push
git push origin master
推送标签
git push origin v1.4
git push origin --tags
移除远程分支
git push origin :dev
git push origin --delete dev
commit
git commit
会跳到默认的文本编辑器,填写更新信息
git commit [[--message | -m ] "update" ]
git commit -a -m 'update'
git commit --amend
git commit -v
config
初始化
git config --global user.name "username"
git config --global user.email email@email.cc
设置别名
git config --global alias.br branch
查看配置
git config --list
git config <key>
git config --global core.editor vim
git config credential.helper store