Does Git have any command equivalent to Mercurial's "hg id"? I.e. a command that prints the parent commit's hash and a plus sign if there are changes in the working directory?
-
8`git rev-parse HEAD` can report the hash. – DCoder Jan 15 '13 at 08:07
-
Thanks everyone for the answers. I was looking for a quick equivalent, to let me know the hash of the parent commit and if the working directory has been modified compared to this. I guess the answer is that I can get that information by combining other commands. – Kostas Jan 15 '13 at 09:01
-
6@DCoder Should add that as an answer. – Laurens Holst Jan 15 '13 at 10:41
5 Answers
This command is equivalent to hg id --id
:
git describe --abbrev=12 --always --dirty=+

- 2,625
- 1
- 15
- 11
git log -1 HEAD^
will show you the whole commit including the SHA-1
If it's a merge, you can see the second parent's commit info with
git log -1 HEAD^2
If you have an octopus merge with more than 2 parents you can put any number in the tree-ish spec:
git log -1 HEAD^5
... to see the 5th parent's commit info
the -1
just limits the log output to one commit. You don't want the lineage of that commit reported.

- 124,556
- 26
- 146
- 141
-
1The question is about a parent of the working dir (the hg way of thinking), so it is asking for the HEAD itself (and its diff wrt working dir, of course). – Dawid Toton Aug 16 '18 at 12:18
I don't think there's a command exactly like that, but you can use:
git status --porcelain
which outputs a machine-readable listing of changed files in the repository. You can look for anything in the first column that is not ?
to indicate a changed file.

- 951,095
- 183
- 1,149
- 1,285
git status
would show the changes in the working directory, and the branch info.
I guess git log
can be used to see the last few commits.

- 12,923
- 3
- 46
- 74
git ls-remote REPOSITORY BRANCH
will show the hash of the head of a given branch.

- 321
- 3
- 7