IntelliJ IDEA create patch from difference

Viewed 7398

I have IntelliJ IDEA Ultimate 2018.2.3. I am trying to create a patch from a difference (Compare with...) in IDE, but I can not find a button to do so. I have several commits on branch_A already. I do not need to create a patch from local changes, I need to create the patch from difference with another branch.

In git it simple git diff branch_A branch_B >> diff.patch

Is there any way to achieve it in the IDE?

4 Answers

In IntelliJ IDEA 2020.2 I was able to make it like this:

  1. Make sure you have no current local changes beforehand: commit them or put them to stash.
  2. VCS -> Git -> Branches -> [select branch to compare with] -> Show Diff with Working Tree
  3. [in opened difference view select needed files] -> [right mouse button] -> Get from Branch
  4. VCS -> Create Patch from Local Changes...

Merge your branch with changes to source branch using VCS -> Git -> Merge changes with Squash commit option. After merge no commit will be done, but you will see changes in a single Changelist. You can click on this Changelist with right mouse button and select Create Patch from local changes option to export patch file. Then you can just revert.

Here's how to do it on IntelliJ 2020.1.3

  1. Commit all you work in your current branch (say, my-committed-branch)
  2. Check out the branch against which you want to generate the diff as a patch (say, master)
  3. Create a new branch from the base i.e. master as say my-uncommitted-branch
  4. Go to VCS -> Git -> Checkout files from branch and choose my-committed-branch. It will show the list of files you have changed. Select all and click ok. You will now have all your changes as uncommitted changes
  5. Now select VCS -> Create Patch from local changes
Related