0

Is there an easy way to manage many git commits locally to then push individually in the order they were created, with the date and time set to the current datetime for each commit when I push it?

The original order and ability to do it individually at different times is important.

I am also open to using an equivalent versioning of code tool on top of the git project if a solution makes sense. The goal is to make this the least stress possible.

  • 1
    Does this answer your question? [How can one change the timestamp of an old commit in Git?](https://stackoverflow.com/questions/454734/how-can-one-change-the-timestamp-of-an-old-commit-in-git) – Acorn Apr 04 '20 at 22:35
  • Just go ahead and keep committing locally. When it's time to upload them, push. The commits will be in the order in which you created them — that is what git is, a rememberer of commits in order. There is no problem with pushing them all so there is no need to push them "individually"; they will retain their individuality — that is what git is, commits. Nothing will harm their integrity. There is no need to reset the date and time (though that is also possible: you could rewrite all the commits just before pushing, as suggested by the duplicate or the answer). – matt Apr 05 '20 at 02:10
  • @acorn potentially but importantly I have a sequence of commits and I would want to push them to the remote individually or in batches in the order they were made. That is because I am doing work in advance of when I should and then need my commits to "look natural" in work hours. I had tried to give that context but my question was edited. – Funeralsandthegrandcanyon Apr 05 '20 at 05:50

1 Answers1

0

You can commit into your branch as usual at the schedule that you need. Then, before pushing to the origin, you can do an interactive rebase:

git rebase -i <first commit hash>

For example, git rebase -i HEAD~10.

This will open a text editor (Vim probably), in which you can select the commits and change the default pick option with edit/e to edit the commits in which you want the date to be modified.

When you're finished, you can close the rebase editor, and then git will go commit by commit giving you the option to edit each one of them. For the first one, you can do:

git commit --amend --date "April 5th 2020 13:00"

And then git rebase --continue to go to the next commit. And then the next, and then the next... until you finish.

After that, you can git push to your branch at origin, or force push if you pushed before.

Of course, this is quite tedious, so you can also squash commits to reduce this work.

Adam
  • 737
  • 1
  • 6
  • 20
  • I dont mind tedious if it works well. Could you show me step by step how you would rebase to achieve for instance, 2 commits but I would want to push only the first one and then the second one at a later time? Is that a case of rebase both but push only 1 and then rebase the second commit again to get the latest datetime before pushing? – Funeralsandthegrandcanyon Apr 05 '20 at 06:12
  • If the commits are the last two, you can do `git rebase -i HEAD~2`, this will start the interactive rebase with Vi, change the `pick` keyword with `edit`, save and exit Vi, then git will revisit these two commits, where you can execute the git amend. To pick which commits to push, instead of everything at once, you’ll need an extra step, you can have a look here: https://stackoverflow.com/questions/604399/how-do-you-push-only-some-of-your-local-git-commits You have many alternatives there. – Adam Apr 05 '20 at 08:59