Created
September 11, 2012 01:08
-
-
Save eboto/3695233 to your computer and use it in GitHub Desktop.
Sets up a git repo with a particular branch layout. Use it to play with merging vs rebasing
This file contains 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
# make_git_test_tree.sh | |
# | |
# This script sets up a git repository with a particular branch layout. Playing around with rebasing and merging | |
# the branches should help your understanding of git. | |
# | |
# Make sure you're in a goddamned empty directory when you execute this script. The script | |
# shouldn't be in the same directory. | |
# | |
# Here's an example, assuming this file is in the current working directory: | |
# | |
# > mkdir gittest | |
# > cd gittest | |
# > ../make_git_test_tree.sh | |
# | |
rm -rf muhfiles .git | |
git init | |
function make_commit { | |
GIT_COMMIT_NAME=$1 | |
echo "Making commit $GIT_COMMIT_NAME" | |
touch muhfiles/$GIT_COMMIT_NAME && git add muhfiles/$GIT_COMMIT_NAME && git commit -a -m "$GIT_COMMIT_NAME" | |
} | |
# Make the repo. It looks like this: | |
# | |
# master A -- B -- C -- D | |
# \ | |
# topic1 M -- N -- O | |
# \ | |
# topic2 X -- Y | |
# | |
mkdir muhfiles | |
make_commit A | |
make_commit B | |
git checkout -b topic1 | |
make_commit M | |
make_commit N | |
git checkout -b topic2 | |
make_commit X | |
make_commit Y | |
git checkout topic1 | |
make_commit O | |
git checkout master | |
make_commit C | |
make_commit D | |
# Rebase topic2 onto master. | |
git checkout topic2 | |
git rebase master | |
# Now it looks like this, where the ' indicates new commit hashes that were generated by rebase. | |
# PRO-TIP, you don't want to be in this state EVAR: | |
# | |
# master A -- B -- C ------ D | |
# \ \ | |
# topic1 M -- N -- O \ | |
# \ | |
# topic2 M' -- N' -- X' -- Y' | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oops...fix in dox suggested by @sphing.