Skip to content

Instantly share code, notes, and snippets.

@mishrsud
Created June 6, 2017 02:24
Show Gist options
  • Save mishrsud/85ee6520a659e86c34ab893a99caf91e to your computer and use it in GitHub Desktop.
Save mishrsud/85ee6520a659e86c34ab893a99caf91e to your computer and use it in GitHub Desktop.

Summary

This document addresses scenarios such as below:

  1. You branched as branch-123 from develop on a repository
  2. To get your changes tested along with some other branch-345, you merged branch-345 into yours
  3. When the time came to review your branch-123 against develop, there are changes from branch-345 as well (which isn't yet merged to develop)
  4. Hence, you need to remove commits from branch-345 to have the PR show only the diff between branch-123 and develop

Solution

Assume the git log looks like the following

commit e5d260c2d19c388ed316bc09e62bddd653e746de << THIS IS HEAD
Author: jon.doe@company.com
Date:   Tue Jun 6 12:10:42 2017 +1000

    branch-345 merged changes from 345

commit 06e1549de226ef625f5a433cd97e1a5b8da1a4b3 << THIS IS WHERE YOU WANT IT TO BE
Author: Sudhanshu Mishra <sudhanshu.mishra@ofx.com>
Date:   Fri Jun 2 10:53:00 2017 +1000

    branch-123 Changes to fix bug
  1. Hard reset to your commit before the merge
# WARNING: THIS WILL OVERWRITE HISTORY!!!
git reset --hard 06e1549de22
  1. Force push to remote
# WARNING: THIS WILL OVERWRITE HISTORY ON REMOTE!!!
git push origin feature/branch-123 --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment