sentenz / convention

General articles, conventions, and guides.
https://sentenz.github.io/convention/
Apache License 2.0
4 stars 2 forks source link

Create an article about `Merge Methods` #284

Open sentenz opened 1 year ago

sentenz commented 1 year ago

Merge Methods

Merge methods refer to the specific procedures or commands used to perform the integration of changes in Git. They determine the actual merge process and the resulting structure of the commit history.

1. Category

1.1. Implicit Merging

Implicit merging involves incorporating changes from one branch into another in a straightforward, sequential manner with a linear history.

1.1.1. Fast-Forward Merge

Moves the branch pointer forward without creating a new commit if possible.

  1. Commands and Operations

    git checkout main
    git merge --ff feature
  2. Representations and Diagrams

    • Before Merge

      gitGraph
        commit id: "A"
        branch feature
        checkout feature
        commit id: "B"
        checkout main
        commit id: "C"
        checkout feature
        commit id: "D"
        checkout main
        commit id: "E"
        checkout feature
        commit id: "F"
    • After Merge

      gitGraph
        commit id: "A"
        commit id: "B"
        commit id: "C"
        commit id: "D"
        commit id: "E"
        commit id: "F"

1.1.2. Squash Merge

Combines all changes from a feature branch into a single commit before merging, maintaining a cleaner commit history.

  1. Commands and Operations

    git checkout feature
    git merge --squash feature
    git commit -m "feat: create API rate limits using RPM (requests per minute)"
    git checkout main
    git merge --ff feature
  2. Representations and Diagrams

    • Before Merge

      gitGraph
        commit id: "A" type: HIGHLIGHT
        branch feature
        checkout feature
        commit id: "B"
        checkout main
        commit id: "C" type: HIGHLIGHT
        checkout feature
        commit id: "D"
        checkout main
        commit id: "E" type: HIGHLIGHT
        checkout feature
        commit id: "F"
    • After Merge

      gitGraph
        commit id: "A" type: HIGHLIGHT
        commit id: "C" type: HIGHLIGHT
        commit id: "E" type: HIGHLIGHT
        commit id: "G" type: HIGHLIGHT

1.1.3. Rebase Merge

Incorporates changes by rewriting the commit history of the feature branch and then fast-forward merging into the target branch.

  1. Commands and Operations

    git checkout feature
    git rebase main
    git checkout main
    git merge --ff-only feature
  2. Representations and Diagrams

    • Before Merge

      gitGraph
        commit id: "A"
        branch feature
        checkout feature
        commit id: "B"
        checkout main
        commit id: "C"
        checkout feature
        commit id: "D"
        checkout main
        commit id: "E"
        checkout feature
        commit id: "F"
    • After Merge

      gitGraph
        commit id: "A"
        commit id: "C"
        commit id: "E"
        commit id: "B"
        commit id: "D"
        commit id: "F"

1.2. Explicit Merging

Explicit merging involves integrating changes from multiple branches in a more complex manner, often creating non-linear history branch structures.

1.2.1. Merge Commit

  1. Commands and Operations

    git checkout main
    git commit -m "chore: merge `feature` into `main`"
    git merge --no-ff feature
  2. Representations and Diagrams

    • Before Merge

      gitGraph
        commit id: "A"
        branch feature
        checkout feature
        commit id: "B"
        checkout main
        commit id: "C"
        checkout feature
        commit id: "D"
        checkout main
        commit id: "E"
        checkout feature
        commit id: "F"
    • After Merge

      gitGraph
        commit id: "A"
        branch feature
        checkout feature
        commit id: "B"
        checkout main
        commit id: "C"
        checkout feature
        commit id: "D"
        checkout main
        commit id: "E"
        checkout feature
        commit id: "F"
        checkout main
        merge feature id: "G"
        checkout main

1.2.2. Semi-Linear Merge

A semi-linear merge in Git is a mix of a rebase and a merge.

  1. Commands and Operations

    git checkout feature
    git rebase main
    git checkout main
    git merge --no-ff feature
  2. Representations and Diagrams

    • Before Merge

      gitGraph
        commit id: "A"
        branch feature
        checkout feature
        commit id: "B"
        checkout main
        commit id: "C"
        checkout feature
        commit id: "D"
        checkout main
        commit id: "E"
        checkout feature
        commit id: "F"
    • After Merge

      gitGraph
        commit id: "A"
        commit id: "C"
        commit id: "E"
        branch feature
        checkout feature
        commit id: "B"
        commit id: "D"
        commit id: "F"
        checkout main
        merge feature id: "G"
        checkout main

2. Terminology

Understanding these terms can help developers navigate and communicate effectively when working with Git merging strategies.

Understanding these terms provides a comprehensive overview of merging strategies and merge methods in Git.

3. References

sentenz commented 1 year ago

Related #7