分布式版本控制

合并

丢弃变更

git reset [--soft] | [--mixed] | [--hard] [<commit>]

撤回提交

last commit

git commit --amend

修改最近一个提交的消息。

revert

git revert [-m parent_number] <commit>

撤回一个commit生成一个新的commit。另,撤回merge-commit后再恢复分支的情况

rebase

git rebase -i (before_commit, last_commit] [--onto newbase] [<branch>]

在特定的基点newbase上重新应用(before_commit, last_commit]补丁。

场景:

  • 在分支上修改内容过程中,主干分支已更新,基于主干HEAD重新应用补丁
    git rebase master
    
  • 修改当前分支的commit历史
    git rebase -i HEAD^^
    
  • 将指定范围内的补丁应用到特定分支上
    git rebase -i HEAD~5 HEAD --onto HEAD~7
    

查看差异

git diff 
git diff --staged
git diff HEAD

临时存放工作目录的改动

git stash