python / python/cpython

venv overwrites existing .gitignore

未关闭
#135,604 26 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

3.13 3.14 3.15 docs stdlib topic-venv
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description

I cloned a github project with an existing .gitignore file.
I created a new python venv inside the cloned project using python3 -m venv .venv .
After creating the new venv, I see that the .gitignore file has been modified.

diff --git a/.gitignore b/.gitignore
index d0258704..f514b74c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,17 +1,2 @@
-.dev
-.idea/
-.hypothesis/
-__pycache__/
-db.sqlite3
-*.sw*
-*.pyc
-venv/
-.venv/
-environment_settings.py
-elm-stuff/
-.coverage
-media
-docker/.env
-node_modules
-package-lock.json
-.sass-cache
+# Created by venv; see https://docs.python.org/3/library/venv.html
+*

I found this documentation on the mentioned url added to the .gitignore file:

Changed in version 3.13: venv now creates a .gitignore file for Git by default.

Environment

  • Arch linux 6.14.9
  • Python 3.13.3

Expected behaviour

I would expect it to not overwrite an existing .gitignore file, so it only creates it if it isnt present already.

Update

Using python3 -m venv .venv works as expected, but I did python3 -m venv .venv . (trailing dot) which creates a folder with a new venv named .venv, but also creates a venv inside the existing folder ., and that's when it overwrites the .gitignore

Please let me know if I'm missing some details or you need further testing for triage the issue.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs
  • gh-139130

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

在一个已经包含 .gitignore 的项目中使用 python3 -m venv .venv . 重现该行为,然后将其与 python3 -m venv .venv 进行比较。跟踪 python3 -m venv 的入口点,并验证创建环境不会替换现有的 .gitignore;确认 Python 3.13 中的行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。