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

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

之后我添加了。gitignore的路径

/wordpress/wp-content/uploads

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

我做错了什么?

我也试过

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

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


当前回答

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

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

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

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

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

其他回答

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

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

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

这对我来说很管用:

git rm -r --cached --ignore-unmatch folder_name

——ignore-unmatch在这里很重要,如果没有这个选项,git将在索引之外的第一个文件上退出并报错。

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

git rm——fileName

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

git commit -m "UntrackChanges"

git push

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

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!

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

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

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

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

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