Skip to content

Instantly share code, notes, and snippets.

@kuya-joe
Last active June 28, 2023 14:45
Show Gist options
  • Save kuya-joe/9305a914f8d92e5752d50f1367cdf577 to your computer and use it in GitHub Desktop.
Save kuya-joe/9305a914f8d92e5752d50f1367cdf577 to your computer and use it in GitHub Desktop.
pseudo script to manually get difference between files itself and then apply those changes to fix conflicts

Using git you can just diff between branches. So you have the diff between the destination branch from your feature branch and you just want to "put your code changes" together Accordin to https://stackoverflow.com/a/22390257/1345527

To create the patch : git diff dev > master.patch To apply it : patch < master.patch

In theory, if diff and git diff are similar you could do the following to put your code changes on top of a target branch (usually when doing a MR to master).

  1. git checkout master (or other target branch)
  2. git diff (your-source-branch ) > final-destination.patch
  3. patch final-destination.patch

Patch is a linux command


NAME
       patch - apply a diff file to an original

SYNOPSIS
       patch [options] [originalfile [patchfile]]

       but usually just

       patch -pnum < patchfile

Another answer on the same question recommends simply using git.

Git kraken has a post on using git patches: https://www.gitkraken.com/learn/git/git-patch#Git-Create-Patch

Take note that applying patches is technically going to result in the same result as fixing merge conflicts,

but it will just one commit. Git merge on the other hand will bring in all your commit history into the branch, which make it harder to revert, especially if the commits aren't tagged with a ticket number properly.

Now if ever your changes in your feature branch are to be discarded, it's just a simple git revert away

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