Search code examples
gitgithubversion-control

git reset all commits in diff of two branches


My usual workflow, when working with others, is to make a feature branch, and have both parties commit changes to this branch. When working together, it's typical to have meaningless commits, as in 'hey I made this small change, what to you think?' However, before we PR and merge this back into master, I'd do a git reset back to the first commit before we started working, and split up the history into reasonable and logical chunks.

However, this time a certain coworker merged in master, making our history unreadable. Or at least I'm now unable to git reset because our commits are no longer all in a row.

Our branch is a superset of master, there are only additional commits. I'd like to remove all those commits but leave the work, allowing me to commit the changes into logical chunks.

Thoughts?


Solution

  • For future folks, I found the best way to approach my problem was to just make a patch of the differences between master and my own, then apply the changes to a new branch, and PR that. This way I could get all my changes but clean up the history a bit.

    git diff --binary master my-branch > ../thing.patch

    then

    git apply ../thing.patch

    I know my problem was a bit wonky, and so was my solution. However, hopefully this'll help someone in the future.