git学习之路 (如何把未提交的代码,合到其他分支上)

如何把某一次commit提交,合到其他分支上

cherry-pick

假设有两个分支 master 与 test,现在要将 master的 一次commit 合到 test 分支上。

  1. 使用 git log 查看要合并过去的 commitId

  2. checkout test

  3. 合并后处理
    3.1 如果没有冲突

     git chery-pick commitId
    

    3.2 有冲突
    解决冲突后 git add . 然后 git cherry-pick --continue
    之后就可以愉快的push啦

把未 commit 的代码,合并到其他分支上

  1. git stash 把未提交的代码暂存起来
  2. 使用 git checkout 切换分支
  3. 将暂存的代码 恢复到当前分支
    git stash list 查看暂存的代码
    git stash apply 恢复后记录依旧存在,需要使用 git stash drop 来删除
    git stash pop 恢复后自动删除暂存代码

你可能感兴趣的:(git学习之路 (如何把未提交的代码,合到其他分支上))