简体   繁体   中英

Git ignore the deletion of a tracked file

scenario

I've a folder /build that is regenerated at each build process. 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.

problem

When the content is generated it deletes the .gitkeep file that was previously tracked by git. 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.

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

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?

The script would be very simple, along the lines of (in a unix system):

#!/bin/sh
touch build/.gitkeep

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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