Is it possible to make a git diff that results in no changes?

Is it possible to create a diff for a commit that simply removes and adds the same exact code.

git does not save a diff for each commit but a complete tree of folders and files (although in a very clever and efficient way). The diff you see is calculated on the fly by comparing the two trees referenced by the commit in question and its parent.

You can create a commit that does not change the code at all (i.e. it references the exact same tree as its parent commit) using the --allow-empty option. But this will give you no reference to any files or lines of code.


Is it possible to create a diff for a commit that simply removes and adds the same exact code thereby giving you an opportunity to create a commit that is really just metadata to specific lines of code, i.e. way to create a comment that is ephemerally attached to the lines of code until those lines are changed?

Simply, No. Your example of a comment would be a code change and thus it would show up in the diff.

Some potential options:

  1. You could create an empty commit as described in SebDieBln's answer, which has no changes and only a commit message, in which you could say whatever you'd like.
  2. You could create 2 commits, where the second one undoes the first. One way to accomplish this is to make some changes in 1 commit, and then revert that commit which will make a 2nd commit. In this case, the diff between the parent of the first commit and the second commit will have no changes, but the diff between the parent of the first commit and the first commit will have your changes you wish to capture and possibly do something with.