跳到主要内容

3 篇博文 含有标签「git」

查看所有标签

从 git 提交记录中删除文件或者文件夹

· 阅读需 1 分钟
1adybug
子虚伊人

有的时候我们会不小心误操作,将某些文件(夹)加入了 git 的提交记录,这并不是我们想要的,即使再添加进 gitignore 也无济于事,以下是解决办法:

# 将 secrets.txt 替换为要删除的文件
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch secrets.txt" --prune-empty --tag-name-filter cat -- --all
# 或者添加 -r 参数,删除文件夹
git filter-branch --force --index-filter "git rm -r --cached --ignore-unmatch logs" --prune-empty --tag-name-filter cat -- --all
# 或者使用 zixulu 工具
npx zixulu rm-git secrets.txt
# 添加 -r 参数,删除文件夹
npx zixulu rm-git logs -r
注意

文件(夹)会被全部删除,包括当前分支,请提前做好备份

在 linux 中安装 nvm

· 阅读需 1 分钟
1adybug
子虚伊人

由于国内的网络环境限制,直接安装 nvm 脚本会失败:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

此时可以使用国内的 gitee 镜像源:https://gitee.com/mirrors/nvm

git clone https://gitee.com/mirrors/nvm
cd nvm
bash install.sh