git如何移除某文件夹的版本控制

news/2025/2/26 7:26:44

目录结构如下

project
    bin
    lib
    src
    ...... 

执行如下的操作

git add .
git commit -m "add bin/ lib/ src/"
git push origin master

突然发现原来 lib 目录不需要提交到版本库,但是现在远程已经存在该目录,what should I do.(吐出去的东西还能收回来吗)

万能的Git啊,help me!

功夫不负有心人,找到了解决问题的方法,其实就是 git rm 的命令行参数。

git rm 命令参数

-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. 
--cached 
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.

解决方法

git rm -r -n --cached "bin/" //-n:加上这个参数,执行命令时,是不会删除任何文件,而是展示此命令要删除的文件列表预览。
git rm -r --cached  "bin/"      //最终执行命令. 
git commit -m" remove bin folder all file out of control"    //提交
git push origin master   //提交到远程服务器

此时 git status 看到 bin/目录状态变为 untracked

可以修改 .gitignore 文件 添加 bin/ 并提交 .gitignore 文件到远程服务器,这样就可以不对bin目录进行版本管理了。

以后需要的时候,只需要注释 .gitignore 里 #bin/ 内容,重新执行 git bin/ ,即可重新纳入版本管理。


http://www.niftyadmin.cn/n/2135982.html

相关文章

docker应用篇(4):搭建私服镜像中心docker-registry和docker-registry-web

文章目录前言第一节、创建镜像中心第二节、测试完整流程(1) 创建账号(2) 推送镜像(3) 退出登录第三节、扩展内容1. 多个私服的配置前言 搭建一个私服docker镜像中心,并且需要安全认证和后台管理。 本文基于mkuchin/docker-registry-web提供的案例来搭建服务。 htt…

iOS在xib或storyboard里为控件添加圆角、外框和外框颜色

如果要在xib和storyboard里为控件添加圆角和外框宽度,只要这样做就可以: layer.borderWidth 设置外框宽度属性 layer.cornerRadius 设置圆角属性 只要为属性设置value值就可以了。 当然修改完xib里看是看不出来的,要运行才看得到,…

docker应用篇(5):详解镜像中心的管理者docker-registry-web

文章目录前言认识和使用docker-registry-web1. 修改密码2. 认识角色3. 查看事件4. 新建角色并控制访问权限前言 docker-registry-web管理者docker镜像中心,本章详解docker-registry-web的使用。 如何搭建docker-registry-web,请见:docker应用篇(4):搭建…

Windows上Python2.7安装Scrapy过程

需要执行: pip install scrapy pip install requests 在Windows下用pip安装Scrapy报如下错误,看错误提示就知道去http://aka.ms/vcpython27找解决方法了 error: Microsoft Visual C 9.0 is required (Unable to find vcvarsall.bat). Get it from http:/…

HTTP协议、Ajax请求

今天这篇文章呢,主要讲的就是关于HTTP协议、Ajax请求以及一些相关的小知识点。虽然内容不算多,可是是很重点的东西~ HTTP协议 1. http:超文本传输协议。简单、快速、灵活、无状态、无连接。2. url:统一资源定位符。 组成部分:协议名://主…

如何进行Android、IOS APP的自动化测试—东舟自动化测试解决方案

金融领域移动端自动化测试解决方案—— 测试能力建设、实现敏捷测试、缩短测试周期银行们的优步(Uber)时刻即将到来,银行的实体网点将被淘汰,移动设备将成为客户和银行之间的主要沟通“中介”。花旗银行全球视角及解决方案部随着智…

docker错误:docker: Error response from daemon: Get “https://xxx:5000/v2/“: http: server gave

错误信息 docker: Error response from daemon: Get “https://106.13.2.249:5000/v2/”: http: server gave HTTP response to HTTPS client. 解决办法: 修改配置 vim /etc/docker/daemon.json添加你的docker私服的ip和端口, 单个私服务 { "insecure-registries&…

spark sql简单示例

运行环境 集群环境:CDH5.3.0 具体JAR版本如下: spark版本:1.2.0-cdh5.3.0 hive版本:0.13.1-cdh5.3.0 hadoop版本:2.5.0-cdh5.3.0 spark sql的JAVA版简单示例 spark sql直接查询JSON格式的数据 spark sql的自定义函数 …