`git filter-repo` 命令在 Windows 上没有输出

13

我通过scoop安装了git-filter-repo,尝试了多个git filter-repo命令,例如git filter-repo -h,但它们都没有记录任何东西,没有警告或错误,只是nothing

尝试过重启、重新安装,并在另一台Windows 10电脑上安装,均复现了此问题。

git-filter-repo: v2.33.0
git: v2.33.0.windows.2
python: v3.9.7
scoop:

Current Scoop version:
09200504 (HEAD -> master, origin/master, origin/HEAD) reset: skip when app instance is running (#4359)

'main' bucket:
b71f4a842 (HEAD -> master, origin/master, origin/HEAD) nunit-extension-vs-project-loader: Update to version 3.9.0

如何解决这个问题?


1
使用命令 git --exec-path 查看 Git 可执行文件的安装位置。然后在该目录中查找名为 git-filter-repo 的文件。我的是一个大约 160 KB 大小的 Python 脚本。如果存在,请打开该文件并查看第一行。如果其中列出了 "python3",请尝试将其更改为 "python"(不带 3)。 - TTT
@TTT 在那个文件夹中不存在git-filter-repo,最终找到了线索,谢谢。这是什么原因造成的? - Wenfang Du
我猜 scoop 没有做你期望的事情。;) 虽然已经过了一段时间,但我很确定我只是从 GitHub 下载了 git-filter-repo,并将该文件放入 Git 文件夹中,进行了一个更改以删除 3,然后它就可以工作了。(假设您已经安装了 Python,您已经安装了。) - TTT
@TTT 太棒了!我完全按照“从GitHub下载git-filter-repo,把文件放到Git文件夹中,做出一个更改以删除3”,现在它可以工作了!你可以为此发布一个答案,但我很想知道为什么scoop没有在git-core文件夹中生成git-filter-repo,以及为什么将python3更改为python会使脚本工作? - Wenfang Du
在git_filter_repo.py文件中,将第一行从python3更改为python真是救了命。 - hahuaz
2个回答

58
(现已更新为较新的Python安装程序。)
当我在今年早些时候在Windows上安装git-filter-repo时,以下步骤适用于我:
  1. Download and install Python for Windows. In newer installers you need to go into the Advanced Options to make sure Python is added to your Path: enter image description here

  2. Confirm python was added to your path and that you can run either the command python --version or python3 --version from your Git command line. (I recommend Git Bash.) In my case, my executable name is python and if yours is too, you will need this in step #7 below.

  3. Clone git-filter-repo from GitHub.

    git clone https://github.com/newren/git-filter-repo.git
    
  4. Run the command git --exec-path to see your Git exe directory.

  5. From the git-filter-repo repo's root directory, copy the file git-filter-repo (about 160KB) into your Git exe directory.

  6. In your command line where you use Git, type the command git filter-repo. If it works, you should get the message "No arguments specified." and you can skip step #7. If it doesn't work, it's likely that your python exe is python instead of python3 as determined in step #2. Go to the next step.

  7. If you get no message or an error message similar to "/usr/bin/env: ‘python3’: No such file or directory", then edit the file git-filter-repo that you copied into your Git exe directory in step #5, and change the first line from "python3" to "python".

现在,让我们惊叹于快速和精彩的git-filter-repo。如果您在第一步中没有添加环境变量,仍然遇到问题,有些人尝试在第七步中将python命令更改为"py",这是Python启动器,可以自动检测您计算机上安装的最高版本。更多信息请参见此处。我应该指出,对于Python 3.10.7,这种方法并不适用。实际上,我首先尝试了这个方法,但最终还是按照上面第一步中描述的方式重新安装并启用了"将Python添加到环境变量"选项。

问题在于第6步没有记录任何消息,这是调试中最困难的情况。 - Wenfang Du
1
哇,这篇文章必须读。所有的文档都是完全针对 Mac 的,所以我真的很感激这些 Windows 步骤 :) - FoxDeploy
2
在Windows上:步骤6,但是出现另一条消息'/usr/bin/env: ‘python3’: Permission denied'也可以通过将python3重命名为python来解决;注意:(如果您在命令行中运行python3,您会发现它不存在,对我来说,在powershell中,Windows Store弹出。但运行"python --version"显示与Store“推广”的相同版本) - JimiSweden
3
如果您安装了 Python 3.10 或更高版本,则似乎需要在文件中输入 "py" 而不是 "python3" 或 "python"。 - FTWinston
1
@FTWinston 我不确定这是否只适用于3.10版本,因为py是早期版本附带的Python启动器,应该能够发现安装的最高版本。这是一个很好的提示,我已经将其纳入答案中。谢谢。 - TTT
显示剩余2条评论

11

在我的情况下,我按照这个Windows 11的答案进行操作,以下是我的经验。

  1. 我从Windows商店或者这个链接https://www.python.org/downloads enter image description here安装了Python。

  2. 我只为当前用户运行了pip3 install git-filter-repo或者python3 -m pip install --user git-filter-repo

我得到了这个消息:

c:\users\username\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages中已经满足要求的git-filter-repo。

  1. 现在复制那个文件夹,但是将site-packages替换为scripts

路径: c:\users\username\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\scripts

你会在 scripts 文件夹中找到 git-filter-repo.exe

  1. 运行 git --exec-path

你将得到:

C:/Program Files/Git/mingw64/libexec/git-core
  1. git-filter-repo.exe 复制到第4步中的文件夹中 (C:/Program Files/Git/mingw64/libexec/git-core)。

现在您应该能够运行 git filter-repo 了。


1
像魔法一样运作良好。 - Ocean Airdrop
2
今天在Windows 10上对我有用-只有一个小差异,它安装在这里:C:\Users\username\AppData\Local\Programs\Python\Python311\Lib\site-packages,而不是c:\users\username\appdata\local\packages...\python310\site-package。我必须将"Lib\site-packages"替换为"Scripts"。不确定这是由于Windows 10还是Python 311与310还是我在安装过程中做出的选择。无论如何,这篇文章帮助了我! - Mark W

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接