我需要排除一个文件夹(名称上传)从跟踪。我试着逃跑
git rm -r --cached wordpress/wp-content/uploads
之后我添加了。gitignore的路径
/wordpress/wp-content/uploads
但是当我运行git状态时,它们显示为已删除。如果我试图提交更改,文件将被删除,而不仅仅是从跟踪中删除。
我做错了什么?
我也试过
git update-index --assume-unchanged <file>
但这似乎只取消跟踪文件。但是我需要从跟踪中删除整个文件夹(包括子文件夹)。
我在谷歌搜索“git从跟踪中删除文件夹”时遇到了这个问题。记者的问题让我找到了答案。我在这里为子孙后代总结一下。
问题
我如何从我的git存储库中删除一个文件夹,而不从我的本地机器(即开发环境)删除它?
回答
步骤1。将文件夹路径添加到repo的根文件.gitignore中。
path_to_your_folder/
步骤2。从本地git跟踪中删除文件夹,但将其保留在磁盘上。
git rm -r --cached path_to_your_folder/
步骤3。将您的更改推到git回购。
从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!