Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Associate an empty git commit with files

Tags:

git

I know that you can use

git commit --allow-empty

to put a commit with no actual file changes into the repository.

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

git log -- <filename>

will display the commit, but I can't figure out a way to do this.

Thanks!

like image 909
Jeff Avatar asked Sep 08 '11 18:09

Jeff


People also ask

How do I allow an empty commit in git?

Git makes this process of pushing an empty commit super simple. It's like pushing a regular commit, except that you add the --allow-empty flag. You can see that the commit has been pushed to your branch without any changes after running the above commands.

How do I add a dummy commit?

Creates an empty commit. Use git commit --allow-empty -m <message> to create an empty commit with the provided <message> .

Can I add empty folder to git?

git can't push empty directories. It can only track files.


1 Answers

From git log --help:

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

You want git log <path>... to show a commit that does not affect the specified paths. That's not going to happen.

What you can do, however, is put the filenames in the commit message and then use git log --grep=<filename>.

Maybe you do not want it in the commit message? Then put it into the commit notes: git notes add -m <filename>. You may have to write a small script to grep for notes, but git plumbing should make that fairly easy.

like image 72
drizzd Avatar answered Sep 21 '22 13:09

drizzd