2

I want to have a simple git post-commit action that prints the date of the last time you pushed your changes to each remote. The motivation for this is a simple reminder of how far out of sync your repo may be becoming or a nice reminder to back up your changes to a remote bare repo.

Does this exist and if not any quick suggestions on how to do this?

If it doesn't exist, my initial thoughts would be:

  • on post-commit, do a 'git log [remote/branch]' for each remote branch in the .git/refs/remotes/ and parse out the date information.

Any help on development strategies for these steps would be welcome (command line linux is my platform)

Thanks!

ricosrealm
  • 1,616
  • 1
  • 16
  • 26
  • `git status` (which I check religiously) already shows how far out of date you are in terms of commits; is that not just as useful? – Eevee Feb 24 '13 at 02:05
  • how would that command work? `git status origin/master` for example did not show me any information on a commit that i did locally but didn't push to the remote. In any event, I'd like it to be an automatic message on a commit so that it is a nice reminder that a push should be done soon. – ricosrealm Feb 24 '13 at 02:38
  • `git status master` should tell you how many commits ahead and/or behind `master` is from its upstream branch. – chepner Feb 24 '13 at 02:58
  • `git status` doesn't take a branch argument. it shows you the status of the current branch, always (since you can't have work in progress on any other branch), and will show you how many commits you've diverged from upstream. if you don't have an upstream set, you can use `git push -u` or the more explicit `git branch --set-upstream ...`. – Eevee Feb 24 '13 at 06:18
  • `git status` from what I'm seeing only prints the outstanding uncommited changes on the current branch. How does this print out the commits that are diverged from another remote branch? Am I missing something here? – ricosrealm Feb 24 '13 at 19:22

2 Answers2

1

As mentioned in "Is there a way in git to obtain a push date for a given commit?", you need for your bare repo (to which you are pushing to) to enable logAllRefUpdates

git config core.logAllRefUpdates true

And then you can have a look at the dates with git reflog

git reflog --date=local master

(but reflog is time limited, 90 days per default)

Other ways usually with rev-parse (as in "How do I get the ID of the last push in git?"), more about the SHA1.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • +1 on the `rev-parse` command. It seems like it might be useful to extract some information for building a post-commit hook to do what I need. However I think all I need is information from `git log [branch]` without enabling any extra tracking. – ricosrealm Feb 24 '13 at 19:29
0

You can use git's post commit hook to display this data once the commit is done. The hooks scripts are located at .got/hooks You can use one of the commands posted here to build the hook script.

stdcall
  • 27,613
  • 18
  • 81
  • 125