简体   繁体   English

Git忽略删除跟踪文件

[英]Git ignore the deletion of a tracked file

scenario 脚本

I've a folder /build that is regenerated at each build process. 我有一个/build文件夹,它在每个构建过程中都会重新生成。 This folder needs to be versioned and the content must be excluded, so in the .gitignore I've added build/* and a /build/.gitkeep to be able to add the folder. 此文件夹需要版本控制,并且内容必须排除,因此在.gitignore我添加了build/*/build/.gitkeep以便能够添加该文件夹。

problem 问题

When the content is generated it deletes the .gitkeep file that was previously tracked by git. 生成内容时,它将删除git先前跟踪的.gitkeep文件。 I would like to know if there is any way to ignore the deletion of this file. 我想知道是否有任何方法可以忽略此文件的删除。 I'm looking for a solution that can works across repos, since git update-index --assume-unchanged <file> only seems to work locally and would need to be executed on each clone. 我正在寻找一种可以在git update-index --assume-unchanged <file>使用的解决方案,因为git update-index --assume-unchanged <file>似乎只能在本地工作,并且需要在每个克隆上执行。

如果将它添加到回购中的检出后挂钩中,则可以在每个客户端上自动运行假定不变的命令。

This sounds more like something you could achieve with your build tool. 这听起来更像是您可以使用构建工具实现的功能。 What are you using to build? 您正在使用什么来构建? could you look into making a script that writes the .gitkeep file to the build/ folder after a build operation has been executed? 您可以考虑制作一个在执行构建操作后将.gitkeep文件写入build/文件夹的脚本吗?

The script would be very simple, along the lines of (in a unix system): 该脚本将非常简单,遵循以下步骤(在UNIX系统中):

#!/bin/sh
touch build/.gitkeep

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM