git 移除文件夹的版本控制

在使用git进行版本控制时可能需要忽略掉某些文件的版本控制,必须编译的文件和一些不必要的缓存文件
例如:[Bb]in/ obj/ .vs/ 等
但如果这些文件已经加入了版本控制再修改 .gitignore 文件则不会生效;
此时可以使用 git rm 命令将已加入版本控制的文件移除版本控制
命令地址:https://git-scm.com/docs/git-rm

git-rm - Remove files from the working tree and from the index

SYNOPSIS
git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…​
DESCRIPTION
Remove files from the index, or from the working tree and the index. git rm will not remove a file from just your working directory. (There is no option to remove a file only from the working tree and yet keep it in the index; use /bin/rm if you want to do that.) The files being removed have to be identical to the tip of the branch, and no updates to their contents can be staged in the index, though that default behavior can be overridden with the -f option. When --cached is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index.

OPTIONS
<file>…​
Files to remove. Fileglobs (e.g. *.c) can be given to remove all matching files. If you want Git to expand file glob characters, you may need to shell-escape them. A leading directory name (e.g. dir to remove dir/file1 and dir/file2) can be given to remove all files in the directory, and recursively all sub-directories, but this requires the -r option to be explicitly given.

-f
--force
Override the up-to-date check.

-n
--dry-run
Don’t actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command.

-r
Allow recursive removal when a leading directory name is given.

--
This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for command-line options).

--cached
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.

--ignore-unmatch
Exit with a zero status even if no files matched.

-q
--quiet
git rm normally outputs one line (in the form of an rm command) for each file removed. This option suppresses that output.

注意:执行命令前最好保持work tree clean

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

具体步骤

git rm -r -n --cached ".vs/" //-n:加上这个参数,执行命令时,是不会删除任何文件,而是展示此命令要删除的文件列表预览。
git rm -r --cached  ".vs/"      //最终执行命令. 
git commit -m" remove bin folder all file out of control"    //提交
git push origin master   //提交到远程服务器
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值