git配置
git config --global user.name my_name
git config --global user.email my_email
git config --global credential.helper store
远程仓库的添加与删除
git remote add origin ****
git remote -v
git remote show origin
git remote show
git remote rename origin test
git remote rm origin
创建一个git仓库
git init
git clone ***
创建分支
git branch test
git checkout -b test
git checkout -b test origin/test
git checkout --track origin/test
追踪远程分支
git branch -u origin/test test
删除分支
git branch -d test
git push --delete origin devel
git fetch -p
重命名分支
# git branch -m test other
暂存修改
git add 1.txt
git reset HEAD 1.txt
git checkout -- 1.txt
删除文件
git rm 1.txt
git rm -f 1.txt
git rm --cached 1.txt
重命名文件
git mv 1.txt 2.txt
差异比较
git diff
git diff --staged
git diff HEAD
git diff HEAD~2 HEAD
gid diff master
提交
git commit -a -m "init"
修改提交
git commit --amend
git rebase -i HEAD~3
git reset
git revert
分支合并
git merge test
git rebase master test
git cherry-pick C1 C2
获取远程仓库内容
git fetch
推送到远程仓库
git push origin test
从远程仓库拉取
git pull origin test
打标签
git tag v1.0 C1
git tag -d v1.0
git push origin --delete tag v1.0
标签推送到远程
git push --tags
获取远程标签
git fetch origin tag v1.0
查看提交历史
git log
git log -p -2 // 显示每次提交的内容差异
git log --stat // 仅显示简要的增改行数统计
git log --pretty=oneline
git log --oneline
git log --pretty=format:"%h %an %s" // 显示每次提交的简短哈希字串 作者的名字 提交说明
git log --pretty=format:"%h %s" --graph // 以图形化的方式显示
git log --author=name --since="2008-10-01" --before="2008-11-01" --no-merges -- t/
gitk // 启动图形化工具
储藏
git stash
git stash save "this is a stash"
git stash list
git stash apply
git stash apply --index stash@{0}
git stash drop stash@{0}
git stash pop --index stash@{0} // 应用并直接删除第一个储藏
git stash show -p | git apply -R // 取消应用储藏
git stash branch test stash@{0} // 基于储藏创建分支 test
git stash clear