You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
Version 1
Next »
Comparing File Structures, Files, and Code in PyCharm
Open Your Project in PyCharm:
- Launch PyCharm and open the project that is under Git version control.
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:
![](/download/attachments/845938756/image-2024-1-24_14-55-17.png?version=1&modificationDate=1706131888134&api=v2)
- 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.
![](/download/attachments/845938756/image-2024-1-24_15-3-6.png?version=1&modificationDate=1706131888048&api=v2)
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.
![](/download/attachments/845938756/image-2024-1-24_15-0-47.png?version=1&modificationDate=1706131888067&api=v2)
- You can expand each file to see the specific lines of code that were changed.
![](/download/attachments/845938756/image-2024-1-24_14-59-8.png?version=1&modificationDate=1706131888088&api=v2)
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.
![](/download/attachments/845938756/image-2024-1-24_14-55-17.png?version=1&modificationDate=1706131888134&api=v2)
- Right-click and select Show Diff with Working Tree.
![](/download/attachments/845938756/image-2024-1-24_15-20-55.png?version=1&modificationDate=1706131887764&api=v2)
- The Working Tree will change to show the difference between your current branch and the one you selected
![](/download/attachments/845938756/image-2024-1-24_15-21-35.png?version=1&modificationDate=1706131887699&api=v2)
- 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
. - Right-click on a file and wil allow you to show the differences and even copy the whole file using Show Diff with Working Tree.
![](/download/attachments/845938756/image-2024-1-24_15-24-45.png?version=1&modificationDate=1706131887665&api=v2)
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...
.
![](/download/attachments/845938756/image-2024-1-24_15-10-31.png?version=1&modificationDate=1706131888015&api=v2)
- Select the other branch you want to compare it with. PyCharm will open a diff viewer showing changes side by side.
![](/download/attachments/845938756/image-2024-1-24_15-11-16.png?version=1&modificationDate=1706131887998&api=v2)
- 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
![](/download/attachments/845938756/image-2024-1-24_15-29-32.png?version=1&modificationDate=1706131887569&api=v2)
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:
- If cherry-picking is not suitable (e.g., you only want specific files from a commit), you can manually copy the file contents.
- Open the file from the commit, copy the contents, switch to your branch, open the same file, and paste the contents.
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.
Manual Code Level Changes:
- Alternatively, you can manually copy and paste specific lines of code.
Open the file from the commit, select the lines you need, switch to your branch, open the file, and paste at the appropriate place.
Related articles
- In the Version Control window, switch to the
Log
tab.