Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6709341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:52:10+00:00 2026-05-26T07:52:10+00:00

I am using git, trying to sync to the first commits of each month

  • 0

I am using git, trying to sync to the first commits of each month for the last year. I want to be able to go back month by month, on the first day of the month, ON THE FIRST SECOND OF THE MONTH. or at least from some constant “seconds” value. So far I have this:

$(git rev-list --before "$(date -d "$(date +%Y-%m-01) -$i months" +%Y-%m)-01" -n 01 HEAD)

This obviously does not include a constant seconds value. As it stands, running this script and then running it again an hour later returns two different sha1’s because it is going back x months FROM THE EXACT TIME at which I run the script. I want the returned sha1’s to be the same no matter when I run this script. Does that make sense? Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:52:11+00:00Added an answer on May 26, 2026 at 7:52 am

    First of all, you have a typo in your command. It has to be --before="$(..., you are missing the =.

    The behaviour of date is not the problem here. date +%Y-%m-01 will return something like 2011-10-01 as a string, there’s no additional time information included. So the second date call will decrease it by the $i number of months and will also return a sting of the format like 2011-09-01. Besides that string no additional information is passed to git-rev-list as value of argument --before=.

    There are some things you have to consider using git-rev-list:

    1. When using HEAD you’re always referring to the current branch. So when you for example checkout one of the obtained commit-IDs your HEAD will change. You maybe want to use master or any other branch name as reference instead.
    2. Git has no temporal order of commits. You can have a commit authored on 1st of August hierarchically after a commit dated 1st of September. This will result in confusing outputs when using --before or --after arguments since they rely on the timestamp of the committer field.
    3. The timestamp of the committer field may also be misleading. When your branch doesn’t have a linear history, it’s hard to tell whether a commit has been part of the branch in a repository at a certain point in history. The author may have pushed/merged his branch X months after doing a commit, so it have not been visible to others.

    Considering all the said, the following command works for me:

    $(git rev-list --after="$(date -d "$(date +%Y-%m-01) -$i months" +%Y-%m)-01 00:00:00" master | tail -n 1)

    This will return the ID of the first commit after the first of the given month. (This commit was not necessarily made during that month, maybe there were no commits in that month anyway.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to sync my desktop and laptop using a cron'd git. It
I'm trying to convert a local SVN repository to git using git-svn under cygwin
I am trying to understand if I really have any case for using git/mercurial.
I've been using SVN since a long time and now we're trying on Git.
I am trying to install git-svn on mac os x 10.5 using the following
I've been using Git on Linux for about a year, and everything works fine.
I have been using git to keep two copies of my project in sync,
I'm trying to get a git commit email hook running using Git on Windows.
I'm trying to convert an existing SVN repository to GIT using git-svn clone but
I'm trying to set up capistrano for pushing my project, using git as VCS.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.