Last active
August 29, 2015 14:10
-
-
Save quis/fc264a9cb1a5cef7aa65 to your computer and use it in GitHub Desktop.
Demonstrating rebasing and no-fast-forward merges in git
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
mkdir temp | |
cd temp | |
git init | |
echo "a" > example-a.txt | |
echo "b" > example-b.txt | |
echo "c" > example-c.txt | |
git add . | |
git commit -am "First commit on master" | |
git checkout -b branch-a | |
git checkout -q master | |
git checkout -b branch-b | |
echo "\n\n" | |
echo "INITIAL STATE OF MASTER" | |
echo "=========================================================================" | |
git checkout master >> /dev/null | |
git log --oneline --decorate --color | cat | |
echo "\n" | |
for I in 1 2 3 | |
do | |
git checkout -q branch-a >> /dev/null | |
echo "a$I" > example-a.txt | |
git commit -am "Commit $I, branch a" >> /dev/null | |
git checkout -q branch-b >> /dev/null | |
echo "b$I" > example-b.txt | |
git commit -am "Commit $I, branch b" >> /dev/null | |
done | |
echo "\n\n" | |
echo "STATE OF BRANCH a" | |
echo "=========================================================================" | |
git checkout branch-a | |
git log --oneline --decorate --color | cat | |
echo "\n\n" | |
echo "STATE OF BRANCH b" | |
echo "=========================================================================" | |
git checkout branch-b | |
git log --oneline --decorate --color | cat | |
git checkout -q master | |
echo "\n" | |
echo "MERGING WITHOUT REBASING" | |
echo "=========================================================================" | |
git merge --no-ff branch-a -m "Merging branch-a" >> /dev/null | |
git merge --no-ff branch-b -m "Merging branch-b" >> /dev/null | |
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit | cat | |
echo "\n" | |
echo "MERGING AFTER REBASING" | |
echo "=========================================================================" | |
git reset --hard HEAD~2 >> /dev/null | |
git checkout -q branch-a | |
git rebase master >> /dev/null | |
git checkout -q master | |
git merge --no-ff branch-a -m "Merging branch-a" >> /dev/null | |
git checkout -q branch-b | |
git rebase master >> /dev/null | |
git checkout -q master | |
git merge --no-ff branch-b -m "Merging branch-b" >> /dev/null | |
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit | cat | |
echo "\n" | |
echo "FAST-FORWARD MERGING AFTER REBASING" | |
echo "=========================================================================" | |
git reset --hard HEAD~2 >> /dev/null | |
git checkout -q branch-a | |
git rebase master >> /dev/null | |
git checkout -q master | |
git merge branch-a -m "Merging branch-a" >> /dev/null | |
git checkout -q branch-b | |
git rebase master >> /dev/null | |
git checkout -q master | |
git merge branch-b -m "Merging branch-b" >> /dev/null | |
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit | cat | |
cd .. | |
rm -rf temp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment