git-cheat-sheet

HEAD

将 HEAD 想象为当前分支的别名

git log

git log -p 显示差异
git log –stat
git log -2
git log –graph 图形显示
git log -Ssearchtext 搜索
git log –grep=text in commit comment 搜索提交信息
git log –since=2016-07-01
git log –author
git log –pretty=online 格式,有很多

git reset

git reset HEAD file1 file2… 移除通过git add添加到暂存区中的修改

git checkout

git checkout – file1 file2… 恢复修改
git checkout -b branchname tagname 检出标签到新建的branchname分支上
git checkout branch_name 检出分支

git fetch & git pull

git fetch 拉取,不和并
git pull 拉取,并尝试合并

git push

git push origin tag_name 推送一个标签
git push origin –tags 推送所有标签
git push origin branch_name 推送分支到远程分支
git push origin local_branch_name:remote_branch_name 推送分支到远程分支
git push origin –delete serverfix 删除远程分支

git remote

git remote
git remote add shortname url
git remote remove name
git remote rename oriname newname

git tag

git tag
git tag -l ‘vx.x.x*’
git tag -a vx.x.y -m ‘comment’
git tag vx.x.z
git tag -a vx.x.a commit_check_sum
git show vx.x.y

alias

git config –global alias.new_command git_command(eg:checkout, branch, reset HEAD –…)
git config –global alias.last ‘log -1 HEAD’

git branch

git branch
git branch new_branch_name 创建分支
git branch -d branch_name 删除分支
git branch -v
git branch –merged/–no-merged 已经合并或未合并到当前分支的分支
git branch -u origin/serverfix 使当前分支跟踪上游分支

git merge

git merge branch_name
git merge origin/branch_name
冲突时:

1
2
3
1. git status查看冲突文件
2. 手动修改冲突文件
3. git add filename标记为冲突已解决

git mergetool –tool vimdiff filename 使用vimdiff合并

git rebase

文章目录
  1. 1. HEAD
  2. 2. git log
  3. 3. git reset
  4. 4. git checkout
  5. 5. git fetch & git pull
  6. 6. git push
  7. 7. git remote
  8. 8. git tag
  9. 9. alias
  10. 10. git branch
  11. 11. git merge
  12. 12. git rebase
,