配置
git config --list
git config user.name
git config user.email
git config --global user.name "Damian"
git config --global user.email "ssdr_liu@163.com" --global home dir setting --system git install dir
常用命令
git init
git add
git status
git commit -m "message"
git clone url
git push -u origin feature1
日志
git log
git log --stat
git log --stat --since=1.minute.ago
分支
git branch
git branch feature1 HEAD~2
git checkout feature1
git merge feature2
people, orgs and teams
git reset --hard HEAD~1
git merge --squash feature1 //HEAD不变
smartgit
git bisect
git reflog //仅记录本地log, e.g., reflog is forward moving
git rebase -i HEAD~2
git rebase master //看起来是顺序开发,其实是并行开发 0-1-。。。-master-bugFix
git checkout master^ // the first parent of master
git checkout master^^ // the grandparent of master
git branch -f master HEAD~3 // move by force the master branch to three parents behind HEAD
高级特性
git reset HEAD //适用于本地修改,不影响远程代码
git revert HEAD //影响远程,因为产生新的提交,该提交还原到上一次提交
git cherry-pick <commit1> <commit2> <...>
类似git rebase, 但cherry-pick可以选择某些提交,而不是全部
git cherry-pick C2 C4
git rebase -i … // interactive rebase
git rebase -i HEAD~4 --aboveall
git pull = git fetch + git merge
远程
将工作目录迁移到github
git remote add github https://github.com/ssdr/note.git
git push github --all --tags
显示所有的远程仓库
git remote -v 重命名
git remote rename github gh 删除
git remote rm github
从远程仓库抓取数据更新本地仓库
git fetch origin
查看远程仓库信息,可用于跟踪别人的push
git remote show origin
Fork的repo和源repo保持同步
- 首先将fork的repo代码clone到本地。默认情况下,
git remote -v
只有origin一个远程库。 - 添加upstream远程库。
git remote add upstream url
。 - 切换到本地master分支,从upstream拉取代码到本地分支。
git branch master
,git fetch upstream
。