Merge the pushed commit in Git

Time:2022-5-10

Sometimes, when fixing some bugs, we need to commit repeatedly, and then launch a pull request, there will be a lot of commit numbers. Some companies will ask to merge these commits. At this time, we can use square to merge the committed commits

  1. First, use git log to view the submitted records

    git log
    commit 7e1c7e33c328f9c1fc954790386b14978612a30f (HEAD -> newbranch)
    Author: yuanjie111 <[email protected]>
    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. Then use git rebase – I head ~ < number >

    git rebase -i HEAD~10
    
    //Head ~ 10 means tracing 10 records from the head

    Merge the pushed commit in Git
    Keep the commit that needs to be left in the pick state, and change the commit that needs to be merged to s, as shown in the figure below. Only one commit is retained,
    Merge the pushed commit in Git
    Then: WQ exit
    3. Push to origin completes the merge.

Recommended Today

VBS tutorial: introduction to regular expressions – common characters

Ordinary character Normal characters consist of all printed and non printed characters that are not explicitly specified as metacharacters. This includes all uppercase and lowercase alphabetic characters, all numbers, all punctuation, and some symbols. The simplest regular expression is a single ordinary character that matches the character itself in the search string. For example, the […]