PyCharm中Git显示旧项目提交日志,如何获取全新提交日志?
Hey there! I’ve run into this exact issue before—when you set up a new project in PyCharm and link Git, it somehow pulls in commit history from an old project. Let’s get your project a fresh, clean Git history in no time.
Step 1: Confirm the Problem
First, let’s make sure we’re dealing with a linked old repository:
- In PyCharm, check the bottom Git panel (click "Log" to see if old commits are showing up)
- Or open a terminal in your project root and run:
If you see commits from your old project, we need to wipe the existing Git data.git log --oneline
Step 2: Wipe Old Git Association & Start Fresh
Here’s how to completely reset the Git setup for your new project:
- Close PyCharm first—this avoids any cached Git state that might cause issues.
- Delete the hidden
.gitfolder in your project directory:- On Windows: Enable "Hidden items" in File Explorer, then find and delete the
.gitfolder. - On Mac/Linux: Open a terminal, navigate to your project root, and run:
rm -rf .git
- On Windows: Enable "Hidden items" in File Explorer, then find and delete the
- Reopen PyCharm and reinitialize Git:
- Right-click your project root in the Project sidebar → Go to
Git→ SelectInitialize Repository. - Confirm the repository location is your new project’s root folder.
- Right-click your project root in the Project sidebar → Go to
Step 3: Make Your First Fresh Commit
Now that Git is set up cleanly, create your initial commit:
- Right-click the project root →
Git→Add(or usegit add .in terminal) - Go to
Git→Commit File... - Enter a message like "Initial commit for [Your New Project Name]" and click
Commit.
Check the Git log again—you should only see this new commit, no old project history!
Bonus: Double-Check for Old Files
If you accidentally copied files from your old project into the new one, make sure to delete any irrelevant files before committing. This keeps your project and Git history clean.
内容的提问来源于stack exchange,提问作者Drearo

