Git equivalent of "hg id"?
Asked Answered
S

5

21

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?

Swayder answered 15/1, 2013 at 8:1 Comment(3)
git rev-parse HEAD can report the hash.Livelihood
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.Swayder
@DCoder Should add that as an answer.Intend
A
14

This command is equivalent to hg id --id:

git describe --abbrev=12 --always --dirty=+

Aidaaidan answered 9/4, 2018 at 15:43 Comment(0)
A
3
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.

Angeli answered 15/1, 2013 at 8:14 Comment(1)
The 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).Rubbing
S
1

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.

Sarver answered 15/1, 2013 at 8:5 Comment(1)
This doesn't return an id. I got as return: "?? workdir/"Houk
K
0

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.

Kcal answered 15/1, 2013 at 8:6 Comment(0)
B
0

git ls-remote REPOSITORY BRANCH will show the hash of the head of a given branch.

https://git-scm.com/docs/git-ls-remote.html

Bogan answered 17/5, 2019 at 7:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.