[英]Git ignore deleted files
I have a website project that has more than 50,000 unimportant files (to development) in some directories.我有一个网站项目,在某些目录中有超过 50,000 个不重要的文件(对开发而言)。
/website.com/files/1.txt
/website.com/files/2.txt
/website.com/files/3.txt
/website.com/files/etc.txt
The stuff in /files is already in the repo. /files 中的内容已经在 repo 中。 I want to delete all the files in /files on my local copy but I want git to ignore it so it doesn't delete them when I do a pull on the web server.
我想删除本地副本上 /files 中的所有文件,但我希望 git 忽略它,这样当我拉取 web 服务器时它不会删除它们。
Any ideas?有任何想法吗?
Ignoring a whole directory didn't work. 忽略整个目录不起作用。 I had to do this:
我不得不这样做:
for i in `git status | grep deleted | awk '{print $3}'`; do git update-index --assume-unchanged $i; done
The code below works on deleted as well as modified files to ignore it when you do a git status . 下面的代码适用于已删除和已修改的文件,以便在执行git状态时忽略它。
git update-index --assume-unchanged dir-im-removing/
or a specific file 或特定文件
git update-index --assume-unchanged config/database.yml
Ignore modified (but not committed) files in git? 忽略git中的修改(但未提交)文件?
Beware: The suggestion above for deleted files when you do a " git commit -am " includes the deleted file! 注意:当您执行“ git commit -am ”时,上面对已删除文件的建议包括已删除的文件!
A solution that would work for me is to instead of deleting the file, just make it's content blank. 对我有用的解决方案是不要删除文件,只是将其内容留空。 This is what I used to mute a .htaccess file.
这就是我用来静音.htaccess文件的方法。
Creating a sub-repo is one solution, but you should make that sub-repo a submodule . 创建子仓库是一种解决方案,但您应该将该子仓库作为子模块 。
That way: 那样:
git submodule update
" (that is without filling the ' files
' content git submodule update
”的情况下检查您的主要仓库(即没有填写“ files
”内容 git submodule update
after the git submodule init
will be enough to get back the right version of the ' files
' content. git submodule update
git submodule init
后的git submodule init
git submodule update
将足以返回正确版本的' files
'内容。 Ok Ive found a solution. 好的,我找到了解决方案。 Simply create a new repo in the sub directories and the parent repo will ignore them.
只需在子目录中创建一个新的repo,父repo就会忽略它们。
To commit only added / modified files (and NOT removed ones) do:要仅提交添加/修改的文件(而不是删除的文件),请执行以下操作:
git add . --ignore-removal
git commit -m "commit message"
for i in `git status | grep deleted | awk '{print $2}'`; do git update-index --assume-unchanged $i; done
works with git 2.25.1适用于 git 2.25.1
if you encounter this issue:如果您遇到此问题:
fatal: Unable to mark file PATH/TO/FILE
致命:无法标记文件 PATH/TO/FILE
check there is no space in the file path and use quotes instead检查文件路径中没有空格并改用引号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.