IntelliJ and Git: How to see diffs between a commi

2020-04-03 05:00发布

问题:

You probably know this window where you can see the diffs between a commit to ONE commit older.

Do you know how can I see exactly the same comparison, but between a commit and a previous commit which is not necessarily ONE before the current one.

I know that I can do it per one file, but I want to do it for the whole project.

回答1:

You can select any number of commits in the git log window (using shift/ctrl and click or cursor keys) and the right-hand pane will show the cumulated differences.



回答2:

In IntelliJ, there is no command or action to compare exact revisions, unfortunately. Here are couple related requests: https://youtrack.jetbrains.com/issue/IDEA-125616 and https://youtrack.jetbrains.com/issue/IDEA-100431

However, there is a way to see what has changed between two commits. To do so you need to go to the Version control - Log tab and select the entire range between wanted commits (e.g select the later commit, then scroll down to the older commit and click on it with Shift). In the right pane showing changed files you will see all the changes.



回答3:

Another way to do it:

  1. Open the 1: Project panel
  2. Right-click your project's root folder
  3. Select GitShow History from the menu

This opens up a completely different view of the git log, where you can do exactly what you'd expect to be able to from the main (9: Version Control) git log... namely:

  1. Select (only!) two commits
  2. Click Compare

From the pop-up dialog that appears, you can select any file and press Ctrl-/Cmd-D (or right-click and select the only menu item) to see the changes.

Unfortunately, there doesn't seem to be any way to "pin" that view to your workspace, though it hovers on top as long as you need it.

Hopefully one day JetBrains will create a "best of both worlds" merged version of these UIs, so we can just compare stuff from the main Version Control log. To add to the list of JetBrains tickets for this issue listed in another answer... the oldest one appears to be https://youtrack.jetbrains.com/issue/IDEA-86480



回答4:

Also in CLion (I think in other JetBrains IDE-s it's the same):

  1. open VCS log
  2. filter VCS log via other branch (e.g., personal/sherstennikov/krt-23941)
  3. top n commits must be the range on other branch we want to diff against current branch
  4. select other branch HEAD with left click
  5. right click on it
  6. select in menu 'Branch ' (e.g.: Branch 'personal/sherstennikov/krt-23941')
  7. expand via arrow on the right and click 'Compare with Current'
  8. you get a window (see pic) 'Comparing with in root ' top left pane contains range of commits from other-branch bottom left pane contains log of current-branch right pane contains list-of-files-which-differ between commit/several-selected-commits (if range selected, list of files is cumulative) in other-branch and HEAD (or maybe selection) in current-branch
  9. now you can click on file in right pane to get it's diff between selected versions in a separate window (let's call it file-diff-between-other-and-current-window) 10.also in file-diff-between-other-and-current-window right on the left of unified/side-by-side viewer selector, there's a control to switch between files in the aforementioned list-of-files-which-differ