Skip to content

Instantly share code, notes, and snippets.

@shivamMg
Created March 25, 2017 06:20
Show Gist options
  • Select an option

  • Save shivamMg/5cc23be1b94a06b489ffea5e0842acf5 to your computer and use it in GitHub Desktop.

Select an option

Save shivamMg/5cc23be1b94a06b489ffea5e0842acf5 to your computer and use it in GitHub Desktop.
Understanding git merge --no-ff
git init
echo a > a.txt
git add a.txt && git commit -m "a"
git checkout -b feature-b
echo b > b.txt
git add b.txt && git commit -m "b"
git checkout master
# ($)
### Two cases possible:
# 1) Plain merge (will fast forward in our case)
git merge feature-b
git log
## <hash> b
## <hash> a
# No merge commit in our case (because fast forward)
# 2) No-ff Merge (will not fast forward even if it's possible (in our case it was possible))
git merge --no-ff feature-b
git log
## <hash> Merge commit
## <hash> b
## <hash> a
# Going back to git checkout master ($)
# Let's commit some work on master
echo c > c.txt
git add c.txt && git commit -m "c"
git merge feature-b
# Now fast forward is not possible
git log
## <hash> Merge commit
## <hash> c
## <hash> b
## <hash> a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment