git Git忽略已删除的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2718372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:15:42  来源:igfitidea点击:

Git ignore deleted files

gitwebignoredelete-file

提问by Petah

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. 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 中的内容已经在 repo 中。我想删除本地副本上 /files 中的所有文件,但我希望 git 忽略它,这样当我在 Web 服务器上执行拉取操作时它不会删除它们。

Any ideas?

有任何想法吗?

采纳答案by Petah

Ok Ive found a solution. Simply create a new repo in the sub directories and the parent repo will ignore them.

好的,我找到了解决方案。只需在子目录中创建一个新的 repo,父 repo 就会忽略它们。

回答by dave1010

Ignoring a whole directory didn't work. I had to do this:

忽略整个目录不起作用。我不得不这样做:

for i in `git status | grep deleted | awk '{print }'`; do git update-index --assume-unchanged $i; done

回答by Quang Van

The code below works on deleted as well as modified files to ignore it when you do a git status.

下面的代码适用于已删除和已修改的文件,以便在您执行git status时忽略它。

 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 文件的方法。

回答by VonC

Creating a sub-repo is one solution, but you should make that sub-repo a submodule.

创建子存储库是一种解决方案,但您应该将该子存储库设为子模块

That way:

那样:

  • you keep a link between your normal content and that 'files' content
  • if the 'files' content evolves one day, you can register its evolution in the main repo
  • you can checkout your main repo without " git submodule update" (that is without filling the 'files' content
  • on deployment, a git submodule updateafter the git submodule initwill be enough to get back the right version of the 'files' content.
  • 您在正常内容和“文件”内容之间保持链接
  • 如果“文件”内容有一天发生了变化,您可以在主存储库中注册其演变
  • 您可以在没有“ git submodule update”的情况下结帐您的主存储库(即无需填写“ files”内容
  • 在部署时, git submodule update之后的 git submodule init将足以取回 ' files' 内容的正确版本。