Merging with git

a minute read

Git merge lets you bring the changes from one branch, on to the other. Merge replays the changes in a branch on top another, starting from the commit where the two branches last diverged. Lets take for instance 2 different branches.

 –  staging

1
2
3
4
5
commit A

commit B

commit C

 live

1
2
3
4
5
6
7
commit A

commit I

commit J

commit K

to merge the the staging branch on to the live branch, you need to:

1
2
3
git checkout live

git merge staging

This will replay the changes made in the staging branch, on top of the live branch at the point where their history last diverged. In this example, both branches diverged from commit A and staging will apply all of its commit snapshots on top of the live branch til the most recent staging snapshot, which is commit C.

Merge will record this replay in a brand new commit along, with the names of the two parent commits and the change log.

git rebase vs merge

Rebasing for a fact creates a cleaner history than merge. The history of a rebased branch consists of a series of linear commits even though the actual work may have happened in parallel. The end result of a merge and rebase will always be the same as they both point to exactly the same diffs, but only the recorded history of snapshots being the difference. Merge always create an additional commit on top of the existing snapshots being brought forward, and also its replay of snapshots on the target branch is not linear.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Comments:

No comments

Related Posts:

To initialize a Git repository in a new project, follow these steps:Open your project directory in a terminal or command prompt.Initialize a new Git repository by running the command: git init.This will create a hidden .git directory, which contains all the ne...
Creating and applying Git tags is a useful way to label specific points in a Git repository's history. Tags can be used to mark significant versions or milestones in a project. Here's how you can create and apply Git tags:Creating a Git tag: To create ...
Git hooks are scripts that can be executed automatically whenever certain actions occur in a Git repository. By using Git hooks, you can automate various tasks and enforce certain workflows in your development process.To use Git hooks for automation, follow th...
To protect the master branch in Git from merging, you can utilize Git's branch protection features to enforce certain rules and restrictions. Here are the steps to achieve this:Open the terminal and navigate to your Git repository.Ensure that you have admi...
To clone a subset of Git branches, you can follow these steps:Open a terminal or Git bash.Navigate to the directory where you want to clone the repository.Clone the repository using the git clone command followed by the repository URL: git clone <repository...
To delete the merge history of a file in Git, you can follow these steps:Open a terminal or Git Bash and navigate to the directory of your Git repository. Use the git log --follow command to view the complete history of the file, including merge commits. Make...