Created
February 8, 2019 22:11
-
-
Save bkietz/d977ae3fa4a2bbe15fbe6dd7e4ac35e1 to your computer and use it in GitHub Desktop.
basic git rebase conflicts
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
source utilities.sh | |
init | |
make_rebase_conflict | |
# observe conflict, panic a little | |
fix_rebase_conflict | |
cd lo | |
# push gets rejected, feel despair | |
git push --force | |
# woo lets get coffee |
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
# create a repo named 'or' and a clone named 'lo' | |
init() { | |
mkdir or | |
pushd or | |
git init | |
touch txt | |
git add txt | |
git commit -am "init" | |
popd | |
git clone or lo | |
} | |
clean() { | |
rm -rf or lo | |
} | |
# stupidly simple repo content editing | |
edit() { | |
repo=$1 | |
file=$repo/txt | |
content=$2 | |
rm $file | |
echo $content > $file | |
pushd $repo | |
git commit -am "$content" | |
popd | |
} | |
# same, with rebase --continue | |
resolve() { | |
repo=$1 | |
file=$repo/txt | |
content=$2 | |
rm $file | |
echo $content > $file | |
pushd $repo | |
git add txt | |
git rebase --continue | |
popd | |
} | |
make_rebase_conflict() { | |
# give 'or' some history | |
edit or 0 | |
edit or 1 | |
edit or 2 | |
edit or 3 | |
# now set up a dev branch for 'or' | |
pushd or | |
git checkout -b dev | |
popd | |
edit or 13 | |
edit or 14 | |
edit or 15 | |
# pull to 'lo' and do some work on dev branch | |
pushd lo | |
git fetch | |
git checkout dev | |
popd | |
edit or 25 | |
edit or 26 | |
edit or 27 | |
# ... meanwhile some work's being checked into master in 'or' | |
pushd or | |
git checkout master | |
popd | |
edit or A | |
edit or B | |
edit or C | |
# now rebase dev onto master | |
pushd lo | |
git checkout master | |
git pull --ff-only | |
git checkout dev | |
git rebase master | |
popd | |
# voila, CONFLICT | |
} | |
fix_rebase_conflict() { | |
# <<<<<<< HEAD | |
# C | |
# ======= | |
# 13 | |
# >>>>>>> 13 | |
resolve lo 13-C | |
# <<<<<<< HEAD | |
# 13-C | |
# ======= | |
# 14 | |
# >>>>>>> 14 | |
resolve lo 14-C | |
# <<<<<<< HEAD | |
# 14-C | |
# ======= | |
# 15 | |
# >>>>>>> 15 | |
resolve lo 15-C | |
# now if you try to push it will be denied because | |
# HEAD at or/dev is "15", which is not an ancestor of "15-C". | |
# git push --force works, though | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment