Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
in DevOps and Agile by (29.3k points)
edited by

Using gitk log, I could not spot a difference between the two. How can I observe the difference (with a git command or some tool)?

2 Answers

0 votes
by (50.2k points)

Git merge will merge the branches whereas git merge with --no-ff

Create a merge commit even when the merge resolves as a fast-forward. This is the default behavior when merging an annotated (and possibly signed) tag that is not stored in its natural place in refs/tags/hierarchy. 

If you want to execute a git pull or use git merge to explicitly fast-forward, and you want to bail out (if it can't fast-forward), then you can use the --ff-only flag. This way you can regularly do something like git pull --ff-only.


+2 votes
by (62.9k points)
  • git merge <receiving_branch>

Git merge combines multiple series of commits into one single history. In the most recent use cases, git merge combines two branches. In these scenarios, git merge takes two commit pointers, usually the latest commits in the two branches, and will find a common base commit between them. Once Git finds a common base commit it will create a new "merge commit" that combines the changes of each queued merge commit sequence.

  • git merge --no-ff <branch>

First, let me tell you what is a fast-forward merge, a fast-forward merge can occur when there is a linear path from the current branch tip to the target branch. Instead of “actually” merging the branches, all Git has to do to integrate the histories which are to move (i.e., “fast forward”) the current branch tip up to the target branch tip. This nicely combines the histories(previous commits), since all of the commits reachable from the target branch are now available through the current one.

Here's an example that shows a fast-forward merge. The code below creates a new branch, adds two commits to it, then integrates it into the mainline with a fast-forward merge.

# Start a new feature

git checkout -b new-feature master

# Edit some files

git add <file>

git commit -m "Start a feature"

# Edit some files

git add <file>

git commit -m "Finish a feature"

# Merge in the new-feature branch

git checkout master

git merge new-feature

git branch -d new-feature

You must not wonder about the git branch -d, since new-feature is now accessible from the master branch.

During situations when you require a merge commit during a fast forward merge for record-keeping purposes, you will execute git merge with the --no-ff parameter.

git merge --no-ff <branch>

This command merges the specified branch int the command into the current branch, but always performs a merge commit (even if it was a fast-forward merge). This is helpful for keeping all merges that are performed in your repository.

Browse Categories