How to view remote Git revision on Heroku
Asked Answered
B

6

93

For deploying to Heroku, I use git push heroku master. But how do I see which revision I pushed up to heroku? (I'm often in doubt if I pushed the recent version up)

For those not familiar with it, Heroku's create script generates a remote git repository that you push to. Upon push, the code is deployed magically.

Heroku adds a remote repository to the local one in the form:

$ git remote add heroku [email protected]:appname.git

More info in Heroku's manual "Deploying with Git"

Question is: How can I see latest version in Heroku repository?

Baseball answered 17/2, 2010 at 15:11 Comment(1)
Note that the latest version in the Heroku repository is not necessarily the same as the version in production. If you run heroku releases:rollback, then the version in production will change, but the Heroku repository will stay absolutely the same. Use heroku:releases to see what is in production.Stesha
M
66

If you've just pushed and want to make sure you're up-to-date, then you can just run git remote show heroku and you'll see output similar to this:

* remote heroku
  Fetch URL: [email protected]:XXX.git
  Push  URL: [email protected]:XXX.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (up to date)

That (up to date) at the end will be replaced by (fast forwardable) if it is not up to date.

Or, if you're wanting to see the full commit log for the heroku remote, the only way I know how is to check it out first. git checkout heroku/master will give you the current commit hash and commit comment: HEAD is now at <short commit hash>... <commit comment>, and git log will give you the rest of the story.

Manny answered 17/2, 2010 at 22:3 Comment(3)
Thanks so much for this answer! I was looking for it everywhere.Niggard
Doesn't actually tell you the refSubmergible
is there any way to see the files themselves online like in a github repo ?Abhenry
E
129

The correct answer is actually so simple. You don't need to checkout anything, neither do you have to resort to COMMIT_HASH hacks (which don't work on Cedar stack). All you need to do is: git ls-remote <remote>

 > git ls-remote heroku
ddaszxcewb585d3a3c00de816a197b14462791a3        HEAD
ddaszxcewb585d3a3c00de816a197b14462791a3        refs/heads/master
Evangelineevangelism answered 7/11, 2011 at 10:58 Comment(4)
so this will show you the version that a particular remote repository is pointed to?Souter
To take the output of this message and easily see the git commit log and textual diff: git ls-remote heroku | awk 'END{print $1}' | xargs git showTapster
@BobbyNorton's comment is the straight-to-the-point answer here. Nice.Gemmagemmate
Note that this is NOT THE SAME AS THE VERSION IN PRODUCTION necessarily. The version in production might be something else, especially if you have just ran a rollback using heroku releases:rollback. Use heroku releases to see what is in production.Stesha
M
66

If you've just pushed and want to make sure you're up-to-date, then you can just run git remote show heroku and you'll see output similar to this:

* remote heroku
  Fetch URL: [email protected]:XXX.git
  Push  URL: [email protected]:XXX.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (up to date)

That (up to date) at the end will be replaced by (fast forwardable) if it is not up to date.

Or, if you're wanting to see the full commit log for the heroku remote, the only way I know how is to check it out first. git checkout heroku/master will give you the current commit hash and commit comment: HEAD is now at <short commit hash>... <commit comment>, and git log will give you the rest of the story.

Manny answered 17/2, 2010 at 22:3 Comment(3)
Thanks so much for this answer! I was looking for it everywhere.Niggard
Doesn't actually tell you the refSubmergible
is there any way to see the files themselves online like in a github repo ?Abhenry
D
46

You may now want heroku releases and you'll see like 5 commits. a start at least.

Downer answered 8/8, 2012 at 11:29 Comment(1)
Thanks. This actually shows me what I want to find out (after doing a rollback what is actually running).Reese
F
25

what about

git log heroku/master
Fatback answered 6/6, 2013 at 9:26 Comment(1)
Depending on how you deploy, the master branch reference may or may not get updated to the SHA that was deployed.Actinology
S
11

if you've run into the situation, like i just did, where a co-worker rolled back your heroku app to a release that doesn't show in heroku releases because they only keep track of 2 releases... the checkout of heroku/master method won't help, because HEAD is not what is deployed anymore.

the undocumented to the rescue:

$ heroku console "ENV['COMMIT_HASH']"
"12abcdef"
Sibelle answered 5/1, 2011 at 22:38 Comment(4)
that's sweet but is there any way to get the last git commit. i checked the ENV doesn't have any variable i can use for date.Kaddish
This doesn't work on Cedar anymore, if there any replacement?Evangelineevangelism
I get 'heroku console' has been disabled (devcenter.heroku.com/changelog-items/109). I tried heroku run "ENV['COMMIT_HASH']" but I get bash: ENV[COMMIT_HASH]: command not found. When I use echo I get the string ENV[COMMIT_HASH].Ediva
You can access the Rails console on the Cedar stack by running heroku run console and you can see what is inside of the ENV['COMMIT_HASH'] variable by running heroku run echo $ENV['COMMIT_HASH'] (since it is an environment variable, you need the '$' - much like echo $PATH).Analcite
H
-1

heroku is using plain old Git underneath, so..

show the latest 5 commits on current branch: git log -5

show commit history via Git's gui: gitk

view current status (it'll show if you have any uncommited files): git status

Hirundine answered 28/3, 2016 at 22:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.