Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does caret bang (^!) after the commit hash do when calling git diff?

Tags:

git

Looking through the source code for brackets-git (a git extension for Brackets), I see that ^! (caret bang) is being appended to the commit hash when calling git diff. See GitCli.js, line 754:

function getDiffOfFileFromCommit(hash, file) {
    return git(["diff", "--no-ext-diff", "--no-color", hash + "^!", "--", file]);
}

This translates to the following on the command line, using the file in question as an example:

$ git diff --no-ext-diff --no-color 1f9ea6e^! -- src/git/GitCli.js

I know that ^ would refer to the parent of the commit. What does ^! do?

like image 612
gilly3 Avatar asked Sep 03 '14 18:09

gilly3


People also ask

What does caret mean in git?

The caret refers to the parent of a particular commit. E.g. HEAD^ refers to the parent of the current HEAD commmit. (also, HEAD^^ refers to the grandparent).

How check diff after commit?

To see the diff for a particular COMMIT hash, where COMMIT is the hash of the commit: git diff COMMIT~ COMMIT will show you the difference between that COMMIT 's ancestor and the COMMIT . See the man pages for git diff for details about the command and gitrevisions about the ~ notation and its friends.

What does git diff head do?

The git diff HEAD [filename] command allows you to compare the file version in your working directory with the file version last committed in your remote repository. The HEAD in the git command refers to the remote repository.

What is a git commit hash?

At a high level, a git commit hash is a SHA1 hash of the state of the git repository at the time of the commit. A short git commit hash is an abbreviation of the hash to the first 7 characters, it is almost certainly unique within a repository and git will increase the number of characters used if it is not.


1 Answers

commit^! is a range specifier which means: this commit, but none of its parents. It's equivalent to specifying: commit ^parent1 ^parent2 ^parentN.

For diff this does not make sense (you can only compare two trees) From testing the command seems to show the differences between the merge base of the parents and the last parent. I think git (mis)interprets the parameters similar to the range A...B which will show the differences between the merge-base A B and B (git diff parent1...parent2 will produce the same diff). Not sure what will happen in the case of an octopus-merge.

I might be wrong though, these are just assumptions I drew from testing with a repository and looking into the git code (builtin/diff.c).

like image 86
knittl Avatar answered Oct 21 '22 10:10

knittl