Skip to content

Instantly share code, notes, and snippets.

@noahpresler
Created July 20, 2017 19:16
Show Gist options
  • Save noahpresler/4f5b9632344d95c37dfb8a45340e0a3a to your computer and use it in GitHub Desktop.
Save noahpresler/4f5b9632344d95c37dfb8a45340e0a3a to your computer and use it in GitHub Desktop.
Create new branch with old commits before history rewrite
git checkout -b {NEWBRANCHNAME} staging
git log --no-merges noah_messed_up..{OLDBRANCHNAME} --format=format:%H | git cherry-pick --stdin
@noahpresler
Copy link
Author

noahpresler commented Jul 20, 2017

Make a copy of your repository directory to be safe

Set {NEWBRANCHNAME} to the name of the new branch which will have your changes
Set {OLDBRANCHNAME} to the name of the branch you wish to reset

After running this and dealing with any conflicts, do:

git log **{NEWBRANCHNAME}..origin/staging**

This compares the commits on the new branch to staging. It should only have your commits you want merged.

git diff {NEWBRANCHNAME} origin/staging

This will show you the diff between the branches. Make sure its the diff you want in a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment