我需要排除一个文件夹(名称上传)从跟踪。我试着逃跑

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

之后我添加了。gitignore的路径

/wordpress/wp-content/uploads

但是当我运行git状态时,它们显示为已删除。如果我试图提交更改,文件将被删除,而不仅仅是从跟踪中删除。

我做错了什么?

我也试过

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

但这似乎只取消跟踪文件。但是我需要从跟踪中删除整个文件夹(包括子文件夹)。


当前回答

要递归地忘记目录,在路径中添加/*/*:

git update-index --assume-unchanged wordpress/wp-content/uploads/*/*

使用git rm——cached不利于协作。更多细节在这里:如何在Git中停止跟踪和忽略文件的更改?

其他回答

要递归地忘记目录,在路径中添加/*/*:

git update-index --assume-unchanged wordpress/wp-content/uploads/*/*

使用git rm——cached不利于协作。更多细节在这里:如何在Git中停止跟踪和忽略文件的更改?

我也是一个初学者,下面是我的解决方案。这个问题应该很容易解决:

In your terminal, make sure you are in the correct folder. For me, it should like: my-MacBook:~ myUserName$ Input: git status It should give you a list of folders and files that git tracking now. Copy them. Input: code .gitignore Your default code editor will open this file, or you can find it and open manually. Paste the list of folders and files name from step 3. Make sure there is no tab or space at beginning of each line. Save and close this file (.gitignore) Go back to the terminal and input: git status If you see the untracked files only have: .gitignore, it means it works now. Input: git add .gitignore Input: git commit -m "what ever message you want to left here" Now you should be all set!

如果文件被提交并推送到github,那么你应该运行

git rm——fileName

Git ls-files,以确保文件被删除或未跟踪

git commit -m "UntrackChanges"

git push

我在谷歌搜索“git从跟踪中删除文件夹”时遇到了这个问题。记者的问题让我找到了答案。我在这里为子孙后代总结一下。

问题

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

回答

步骤1。将文件夹路径添加到repo的根文件.gitignore中。

path_to_your_folder/

步骤2。从本地git跟踪中删除文件夹,但将其保留在磁盘上。

git rm -r --cached path_to_your_folder/

步骤3。将您的更改推到git回购。

从Git的角度来看,这个文件夹将被认为是“删除”的(例如,它们在过去的历史中,但不在最近的提交中,从这个回购中提取的人将从他们的树中删除文件),但仍然保留在你的工作目录中,因为你使用了—缓存。

我知道这是一个旧线程,但我只是想添加一点,因为标记的解决方案并没有解决我的问题(尽管我尝试了很多次)。

我可以停止git表单跟踪文件夹的唯一方法是执行以下操作:

对本地文件夹进行备份并放在安全的地方。 从本地回收中删除文件夹 确保缓存被清除git rm -r——cached your_folder/ 将your_folder/添加到。gitignore 提交修改 将备份添加回您的回购

您现在应该看到不再跟踪该文件夹。

不要问我为什么只是清理缓存对我不起作用,我不是一个Git超级向导,但这就是我解决问题的方法。