Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Comparing & Moving File Structures, Files, and Code Between Two Branches in PyCharm

  1. Open Your Project in PyCharm:

    • Launch PyCharm and open the project that is under Git version control.
  2. Accessing the Version Control System:

    • Go to View > Tool Windows > Git or press Alt+9 (on Windows/Linux) or Cmd+9 (on macOS) to open the Version Control window.

Comparing Branches for Overall Structure:

  • In the Version Control window, switch to the Log tab.
  • Select the two branches you want to compare by holding Ctrl (or Cmd on macOS) and clicking the branch names.
    Image Modified
  • Right-click and select Compare with <BRANCH>or just Compare if you want to compare two branches other than the one you are currently on.
    Image Modified

Viewing File Structure Differences:

  • The differences between the branches will be displayed in a new tab. It shows commits that are unique to each branch.
  • To see file structure differences, click on a commit. PyCharm will show the list of files changed in that commit.
    Image Modified
  • You can expand each file to see the specific lines of code that were changed.
    Image Modified

Comparing Working Tree:

  • In the Version Control window, switch to the Log tab.
  • Here, you'll see a list of branches at the top. Select the branch you want to compare.
    Image Modified
  • Right-click and select Show Diff with Working Tree.
    Image Modified
  • The Working Tree will change to show the difference between your current branch and the one you selected
    Image Modified
  • Click on a file, and the diff viewer allows you to see line-by-line differences in the file between the two branches.
  • Right-click on a file and wil allow you to show the differences and even copy the whole file using  Get from Branch

...

  • .
    Image Modified

Comparing Individual Files:

  • To compare an individual file across branches, find that file in the Project view.
  • Right-click the file and choose Git > Compare with Branch....
    Image Modified
  • Select the other branch you want to compare it with. PyCharm will open a diff viewer showing changes side by side.
    Image Modified
  • This diff viewer allows you to see line-by-line differences in the file between the two branches.
  • You can pick changes from the code using the >> in every single difference
    Image Modified

...

Moving Changes to Your Branch

At a File Level:

...

Cherry-picking a Commit:

  • If an entire file or a set of files were changed in a specific commit and you want to bring those changes into your current branch, you can cherry-pick that commit.
  • Right-click on the commit and select Cherry-pick. This will apply all changes from that commit to your current branch.

Manual File Level Changes:

...

At a Code Level:

...

Partial Cherry-picking:

  • PyCharm allows partial cherry-picking where you can choose specific files or even chunks of code from a commit.
  • Right-click the commit, choose Cherry-pick..., and in the dialog, select the specific files or parts of files you want to cherry-pick.



Comparing File Structures, Files, and Code in Visual Studio Code

  1. Open Your Repository in VS Code:
    1. Start VS Code and open the folder containing your Git repository.
  2. Install GitLens (if not already installed):
    1. GitLens is an extension for VS Code that enhances its Git capabilities.
    2. Go to the Extensions view by clicking on the square icon on the left sidebar or pressing Ctrl+Shift+X (Windows/Linux) or Cmd+Shift+X (macOS).
    3. Search for "GitLens" and install it.
      Image Added


Comparing Branch File Structures:

  • Open the Source Control panel by clicking the branching icon on the left sidebar or pressing Ctrl+Shift+G (Windows/Linux) or Cmd+Shift+G (macOS).
  • In the Source Control panel, you'll find Branches. Click it and select it. 
    Image Added
    • OR right-click on the file and select Open Changes
      Image Added
  • Select the branch you want to compare against, right-click on the file and select Compare with Upstream to compare with your current branch.
  • GitLens will display the file structure differences between the branches, including added, deleted, and modified files.
    Image Added

Comparing Individual Files:

  • Within the changes displayed by GitLens, click on a file to open the diff view.
  • This view will show you the differences in that file between the current branch and the selected branch, side by side.
    Image Added
  • You can move or apply all the changes in a file. Right-click on the file and select Apply Changes
    Image Added

Comparing Code Within Files:

  • The side-by-side diff viewer in VS Code allows you to examine the specific code changes line by line.
  • Changes are highlighted, with additions and deletions clearly marked.
  • You can move code changes from one branch to another by clicking on the arrow on the side of the change
    Image Added

Manual Code Level Changes:

...

Content by Label
showLabelsfalse
max5
spacesSEARCHAPI
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel in ("branches","git","migration") and type = "page" and space = "SEARCHAPI"
labelsgit branches migration

Page properties
hiddentrue
Related issues


    1. In the Version Control window, switch to the Log tab.


Table of Contents