Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyCharm Version Control Integration

PyCharm Version Control Integration

PyCharm provides complete Git/GitHub integration, allowing developers to perform version control operations directly within the IDE.


Configure Git/GitHub

Configure user information

Run in the terminal:



git config --global user.name "Your Name"

git config --global user.email "your.email@example.com"

Integrate GitHub

** 1. Add a GitHub account:**

-

Log in via GitHub: Log in by authorizing through the browser

-

Log in via token: Use a personal access token

** 2. SSH configuration (optional):**


Basic operations

We can create a Git repository using the version control button on the toolbar:

Afterwards, the version control button on the project changes to master (main branch):

Commit and push

Commit code

in Commit tool window(Commit Tool Window):

-

Submit(Commit): Commit locally only

-

Commit and push(Commit and Push): Push to remote immediately after committing

Keyboard shortcut:

View changes

File status color markers:

Pull and merge

Pull the latest code

  1. Git → Pull or Ctrl+T (Win/Linux) / ⌘T (Mac)

  2. Select a merge strategy:

  3. Merge: Keep all commit history

  4. Rebase: Linear history

  5. -

    Merge: Keep all commit history

    -

    Rebase: Linear history

    Merge branches

    1. Git → 分支 → 合并分支

    2. Select the target branch to merge

    3. Resolve possible conflicts (see section 6.3)

    View history and differences

    View commit history

    1. Git → 显示历史 or Alt+9

    2. Function:

    3. View file/project history

    4. Compare different versions

    5. Roll back to a specific version

    6. -

      View file/project history

      -

      Compare different versions

      -

      Roll back to a specific version

      Compare differences

      1. File difference:

      2. Right-click the file -> Git → 比较与当前分支

      3. or Ctrl+D (Win/Linux) / ⌘D (Mac)

      4. -

        Right-click the file -> Git → 比较与当前分支

        -

        or Ctrl+D (Win/Linux) / ⌘D (Mac)

        1. Inline difference:

        2. Modified lines show colored markers

        3. Click a marker to view the specific changes

        4. -

          Modified lines show colored markers

          -

          Click a marker to view the specific changes


          6.3 Resolve conflicts

          1. Conflict scenarios

          2. Resolution steps

          Open the merge tool

          Three-pane comparison interface

          Resolve conflicts

          Mark as resolved

          Commit the merge result

          3. Advanced conflict resolution

          Use an external merge tool

          Accept a whole version entirely


          Practical tips

          Partial commit

          -

          Select specific changes of a file to commit

          -

          Right-click a code block -> 提交选定行

          Stash changes

          -

          Git → 储藏

          -

          Restore:Git → 取消储藏

          Interactive rebase

          -

          Reorder commits

          -

          Squash commits

          -

          Modify commit messages