Reputation: 43427
I'm in the middle of a git bisect
session.
What's the command to find out which commit (SHA1 hash) I am currently on? git status
does not provide this.
Edit: I guess calling git log
and looking at first entry works?
Upvotes: 260
Views: 316299
Reputation: 1323363
If you do use git bisect visualize
, as shown in this answer; make sure to use Git 2.42 (Q3 2023).
"git bisect visualize
"(man) stopped running gitk
on Git for Windows when the command was reimplemented in C around Git 2.34 timeframe.
This has been corrected with Git 2.42 (Q3 2023).
See commit fff1594, commit 2bf46a9, commit bb532b5 (04 Aug 2023) by Matthias Aßhauer (rimrul
).
(Merged by Junio C Hamano -- gitster
-- in commit 8cdd5e7, 09 Aug 2023)
compat/mingw
: implement a nativelocate_in_PATH()
Reported-by: Louis Strous
Signed-off-by: Matthias Aßhauer
since 5e1f28d (
bisect--helper
: reimplementbisect_visualize()
shell function in C, 2021-09-13, Git v2.34.0-rc0 -- merge listed in batch #8) (bisect--helper: reimplementbisect_visualize()
shell function in C, 2021-09-13)git bisect
(man) visualize usesexists_in_PATH()
> to check wether it should callgitk
, butexists_in_PATH()
relies onlocate_in_PATH()
which currently only understands POSIX-ish PATH variables (a list of paths, separated by colons) on native Windows executables we encounter Windows PATH variables (a list of paths that often contain drive letters (and thus colons), separated by semicolons).
Luckily we do already have a function that can lookup executables on windows PATHs:path_lookup()
.
And:
docs
: update whengit bisect visualize
usesgitk
Signed-off-by: Matthias Aßhauer
This check has involved more environment variables than just
DISPLAY
since 508e84a ("bisect view: check for MinGW32 and MacOSX in addition to X11", 2008-02-14, Git v1.5.5-rc0 -- merge), so let's update the documentation accordingly.
git bisect
now includes in its man page:
Git detects a graphical environment through various environment variables:
DISPLAY
, which is set in X Window System environments on Unix systems.SESSIONNAME
, which is set under Cygwin in interactive desktop sessions.MSYSTEM
, which is set under Msys2 and Git for Windows.SECURITYSESSIONID
, which may be set on macOS in interactive desktop sessions.If none of these environment variables is set, 'git log' is used instead. You can also give command-line options such as
-p
and--stat
. Implement a small replacement for the existinglocate_in_PATH()
based onpath_lookup()
.
Upvotes: 0
Reputation: 33607
If you want to extract just a simple piece of information, you can get that using git show
with the --format=<string>
option...and ask it not to give you the diff with --no-patch
. This means you can get a printf-style output of whatever you want, which might often be a single field.
For instance, to get just the shortened hash (%h
) you could say:
$ git show --format="%h" --no-patch
4b703eb
If you're looking to save that into an environment variable in bash (a likely thing for people to want to do) you can use the $()
syntax:
$ GIT_COMMIT="$(git show --format="%h" --no-patch)"
$ echo $GIT_COMMIT
4b703eb
The full list of what you can do is in git show --help
. But here's an abbreviated list of properties that might be useful:
%H
commit hash%h
abbreviated commit hash%T
tree hash%t
abbreviated tree hash%P
parent hashes%p
abbreviated parent hashes%an
author name%ae
author email%at
author date, UNIX timestamp%aI
author date, strict ISO 8601 format%cn
committer name%ce
committer email%ct
committer date, UNIX timestamp%cI
committer date, strict ISO 8601 format%s
subject%f
sanitized subject line, suitable for a filename%gD
reflog selector, e.g., refs/stash@{1}%gd
shortened reflog selector, e.g., stash@{1}Upvotes: 22
Reputation:
You have at least 5 different ways to view the commit you currently have checked out into your working copy during a git bisect
session (note that options 1-4 will also work when you're not doing a bisect):
git show
.git log -1
.git status
.git bisect visualize
.I'll explain each option in detail below.
As explained in this answer to the general question of how to determine which commit you currently have checked-out (not just during git bisect
), you can use git show
with the -s
option to suppress patch output:
$ git show --oneline -s
a9874fd Merge branch 'epic-feature'
You can also simply do git log -1
to find out which commit you're currently on.
$ git log -1 --oneline
c1abcde Add feature-003
In Git version 1.8.3+ (or was it an earlier version?), if you have your Bash prompt configured to show the current branch you have checked out into your working copy, then it will also show you the current commit you have checked out during a bisect session or when you're in a "detached HEAD" state. In the example below, I currently have c1abcde
checked out:
# Prompt during a bisect
user ~ (c1abcde...)|BISECTING $
# Prompt at detached HEAD state
user ~ (c1abcde...) $
Also as of Git version 1.8.3+ (and possibly earlier, again not sure), running git status
will also show you what commit you have checked out during a bisect and when you're in detached HEAD state:
$ git status
# HEAD detached at c1abcde <== RIGHT HERE
Finally, while you're doing a git bisect
, you can also simply use git bisect visualize
or its built-in alias git bisect view
to launch gitk
, so that you can graphically view which commit you are on, as well as which commits you have marked as bad and good so far. I'm pretty sure this existed well before version 1.8.3, I'm just not sure in which version it was introduced:
git bisect visualize
git bisect view # shorter, means same thing
Upvotes: 304
Reputation: 91470
Use git show
, which also shows you the commit message, and defaults to the current commit when given no arguments.
Upvotes: 4
Reputation: 41383
$ git rev-parse HEAD 273cf91b4057366a560b9ddcee8fe58d4c21e6cb
Update:
Alternatively (if you have tags):
(Good for naming a version, not very good for passing back to git.)
$ git describe v0.1.49-localhost-ag-1-g273cf91
Or (as Mark suggested, listing here for completeness):
$ git show --oneline -s c0235b7 Autorotate uploaded images based on EXIF orientation
Upvotes: 31
Reputation: 467031
You can just do:
git rev-parse HEAD
To explain a bit further: git rev-parse
is git's basic command for interpreting any of the exotic ways that you can specify the name of a commit and HEAD
is a reference to your current commit or branch. (In a git bisect
session, it points directly to a commit ("detached HEAD") rather than a branch.)
Alternatively (and easier to remember) would be to just do:
git show
... which defaults to showing the commit that HEAD
points to. For a more concise version, you can do:
$ git show --oneline -s
c0235b7 Autorotate uploaded images based on EXIF orientation
Upvotes: 120