Created
August 16, 2016 04:22
-
-
Save nicolasbock/f89dee10387159eb1782c9c4735ed5b8 to your computer and use it in GitHub Desktop.
Split the last two commits on the master branch into two separate branches
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
#!/bin/bash | |
mkdir split-PRs | |
cd split-PRs | |
git init | |
touch file1 | |
git add file1 | |
git commit -m "Adding file1 (last commit on master)" | |
# PR1 | |
touch file2 | |
git add file2 | |
git commit -m "Adding file2 (PR1)" | |
# PR2 | |
cat<<EOF >> file1 | |
Some more text for file1 | |
EOF | |
git commit --all -m "Adding some text to file1 (PR2)" | |
# Split the last two commits into separate branches. | |
git checkout -b PR1 master^^ | |
git cherry-pick master^ | |
git checkout -b PR2 master^^ | |
git cherry-pick master | |
# Remove those commits from master. | |
git checkout master | |
git reset --hard master^^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment