Link empty git commit to files

I know you can use

git commit --allow-empty 

to put a commit without actual file changes to the repository.

The problem is that I need to be able to create such empty commits that are associated with various files (files) in the repository. In other words, I want to be able to put some kind of empty commits for which

 git log -- <filename> 

will display a commit, but I cannot figure out how to do this.

Thanks!

+7
source share
2 answers

From git log --help :

 [--] <path>... Show only commits that affect any of the specified paths. 

You want git log <path>... display a commit that does not affect the specified paths. This will not happen.

However, you can put the file names in a commit message, and then use git log --grep=<filename> .

Maybe you don't want this in a commit message? Then put it in the commit notes: git notes add -m <filename> . You may need to write a small grep script for notes, but git plumbing should do this quite easily.

+7
source

The reason this cannot be done is because for git, the commit is a snapshot of the status of all the files in the project at that point, and the affected files are later output by comparing the commit with its parent. (The affected files are only those files that are different from each other.) Thus, there is no way to artificially mark the path as affected because the commit does not actually store this information directly.

One thing you can do is change the file permissions (for example, set or disable recording in groups) on the appropriate paths - this will be committed as a change, although the contents of the file will be the same. And you can always have two adjacent commits - one that changes permissions, and the other - to change them - if you don't want permissions to stay changed. This is a bit dirty, but it will work, especially if the file permissions are not important in your case.

+5
source

All Articles