从git跟踪中删除文件夹

从git跟踪中删除文件夹

本文介绍了从git跟踪中删除文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从跟踪中排除文件夹(名称上传)。我试图运行

  git rm -r --cached wordpress / wp-content / uploads 

之后,我添加了到.gitignore的路径

  / wordpress / wp-content / uploads 

但是当我运行 git status 它们显示为已删除。如果我尝试提交更改,这些文件将被删除,不仅会从跟踪中删除。



我做错了什么?



我也试过了

  git update-index --assume -unchanged< file> 

但是这似乎只能查找文件。但我需要删除整个文件夹(包括子文件夹)。

从跟踪中删除文件夹。 OP的问题引导我回答。我在这里为后代进行总结。



问题

我如何从我的git存储库中删除一个文件夹而不从我的本地机器(即开发环境)中删除它?

回答



第1步。将文件夹路径添加到您的仓库根目录 .gitignore 文件。

  path_to_your_folder / 

第2步。从您的文件夹中移除文件夹

  git rm -r --cached path_to_your_folder / 

本地git跟踪,但保留在您的磁盘上。 code>

第3步。将所做更改推送到您的git repo。



文件夹将被视为从Git的角度删除(即他们在过去的历史中,但不是在最新的提交中,并且从这个回购中拉出的人将从他们的树中移除文件),但留在你的工作目录上,因为您已使用 - 缓存


I need to exclude a folder (name uploads) from tracking. I tried to run

git rm -r --cached wordpress/wp-content/uploads

and after that I added the path to .gitignore

/wordpress/wp-content/uploads

but when I ran git status they show up as deleted. If I try to commit the changes, the files will be deleted, not only removed from tracking.

What am I doing wrong?

I have also tried

git update-index --assume-unchanged <file>

but this seems to untrack only files. But I need to remove an entire folder (including subfolders) from tracking.

解决方案

I came across this question while Googling for "git remove folder from tracking". The OP's question lead me to the answer. I am summarizing it here for future generations.

Question

How do I remove a folder from my git repository without deleting it from my local machine (i.e., development environment)?

Answer

Step 1. Add the folder path to your repo's root .gitignore file.

path_to_your_folder/

Step 2. Remove the folder from your local git tracking, but keep it on your disk.

git rm -r --cached path_to_your_folder/

Step 3. Push your changes to your git repo.

The folder will be considered "deleted" from Git's point of view (i.e. they are in past history, but not in the latest commit, and people pulling from this repo will get the files removed from their trees), but stay on your working directory because you've used --cached.

这篇关于从git跟踪中删除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 04:47