git

Git

Posted by hurshi on 2020.07.01

git rebase

  1. 合并未提交到远程的多个 commit

    1
    2
    
    git rebase -i 89fahe8 // 合并从当前 head 到 89fahe8
    git rebase -i HEAD~3 // 合并最近3次提交
    

    然后修改 picks/e/m 等等,可以查看命令下面的提示。

  2. 合并同一个分支的多次提交冲突

    当你和同事在同一个分支上并行开发,分支容易出现分叉:

    1
    2
    3
    4
    5
    6
    
    *   406e997 - (HEAD -> feature1, origin/feature1) Merge branch 'feature1' of ...
    |\
    | * 6e64236 - 同事A的提交 (34 seconds ago) <Hurshi>
    * | 37d77bd - 我的提交 (10 seconds ago) <Hurshi>
    |/
    * b28bebe - fix bug (73 seconds ago) <Hurshi>
    

    如果在 git pull的时候,替换为 git pull --rebase就可以避免分叉了。

  3. 合并分支

    1
    
    git:(feature2) git rebase feature1 // 将 feature1 的变动合并到当前分支来