• git merge [branch-name] 合并一个分支到当前分支,会把被合并分支和你当前分支的commit合并在一起,形成一个新的 commit 提交
  • git rebase [branch-name] 合并一个分支到当前分支,把你当前分支的commit放到被合并分支的最后面
  • git rebase -i HEAD~[num] 将最近num个commit合并成一个(这样推送到远程仓库后只有一个commit,避免污染远端的commit)
  • git pull --rebase 相当于 git fetch + git rebase
  • git checkout <branch-name> [--] <file-name> 从不同分支拉取当个文件
  • git checkout --theirs [file-name] 表示检出另外分支, 即保存另外分支的改动,丢弃当前分支的改动。冲突时直接使用他人的代码
  • git checkout --ours [file-name] 检出当前分支,即保存当前分支的改动,丢弃另外分支的改动。冲突时直接使用自己的代码
  • git cherry-pick <commit-id1> <commit-id2> ... 将指定的一些commit合并到当前分支
  • git cherry-pick <branch-name> 将所选分支的最近一次提交,转移到当前分支
  • 一次合并操作
    git checkout dev
    git rebase master
    #or git merge master
    #or git cherry-pick 8797a4f
    #出现冲突,修改文件后执行
    git add .
    #继续修改合并
    git rebase --continue
    #or git merge  --continue
    #or git cherry-pick  --continue
    #如果不想合并,直接终止
    git rebase --abort
    #or git merge --abort
    #or git cherry-pick  --abort
    
  • git merge与git rebase 使用建议
    公共分支使用merge,个人分支使用rebase
    本地和远端对应同一条分支,优先使用rebase,而不是merge