You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Git仓库中批量移动文件至指定目录?

批量移动仓库文件到指定目录的方法

Linux/macOS 终端操作

方法1:使用扩展通配符(需开启extglob)

  1. 进入仓库根目录
  2. 开启扩展通配符(若未开启):
    shopt -s extglob
    
  3. 执行批量移动命令(排除dir和.git目录):
    mv !(dir|.git) dir/
    

方法2:使用find命令(更稳妥,无需额外配置)

进入仓库根目录后执行:

find . -maxdepth 1 -mindepth 1 ! -name 'dir' ! -name '.git' -exec mv {} dir/ \;

Windows PowerShell 操作

进入仓库根目录后执行:

Get-ChildItem -Exclude dir,.git | Move-Item -Destination dir

Git 提交变更

移动完成后,提交仓库变更:

git add .
git commit -m "迁移所有项目文件至dir目录"

注意:以上命令均会保留根目录的.git文件夹(仓库核心文件),仅移动其他项目文件和文件夹到dir目录。

内容的提问来源于stack exchange,提问作者DgUZH

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 07:55:17