关于git:git-中合并已经push-的commit

2次阅读

共计 794 个字符,预计需要花费 2 分钟才能阅读完成。

有时候在改一些 bug 的时候,须要重复的 commit, 而后发动 pull request 时,commit 号就会十分多,有的公司会要求合并这些 commit,这时咱们能够用 squash 来合并曾经提交的 commit.

  1. 首先 git log 查看曾经提交的记录

    git log
    commit 7e1c7e33c328f9c1fc954790386b14978612a30f (HEAD -> newbranch)
    Author: yuanjie111 <284522843@qq.com>
    Date:   Sat Jun 12 13:55:58 2021 +0800
    
    111
    
    commit 3a30ba5c71349947e512c6b0c481854a19418d10 (origin/newbranch)
    Author: **
    Date:   Sat Jun 12 13:03:01 2021 +0800
    
    config center
    
    commit 2873ff1b3c92e9a4b0c4937a5a4a27d5178efe2b
    Author: ***
    Date:   Sat Jun 12 12:48:29 2021 +0800
    
    config center
    
    commit ba62f39480360977e08f6e1e288869f2fe4a7ed8
    Author: ***
    :...skipping...
    commit 7e1c7e33c328f9c1fc954790386b14978612a30f (HEAD -> newbranch)
    Author: ****
    Date:   Sat Jun 12 13:55:58 2021 +0800
    
    111
    
  2. 而后应用 git rebase -i HEAD~<number>

    git rebase -i HEAD~10
    
    //HEAD~10 的含意是从头部开始追溯 10 条记录
    


    将须要留下的 commit 放弃 pick 状态,须要合并的改为 s 即可,如下图,只保留了一个 commit,

    而后:wq 退出
    3.push 到 origin 则实现了合并。

正文完
 0