-1

Is it possible to change the date of a commit in Git?

If yes does this modification leave any track?

Basically I want to change the date of a commit but it should not be visible to anyone that the date has changed by me.

As I have researched it is possible to change the date by using git filter-branch but I do not know whether this leaves any history.

user229044
  • 232,980
  • 40
  • 330
  • 338
Kejsi Struga
  • 550
  • 6
  • 21
  • 1
    If you're aiming to change a commit that's already been pushed to a shared upstream, you'll have to do a force push, and that will *certainly* be noted by your teammates (or whomever). – Oliver Charlesworth Nov 12 '17 at 14:35
  • @OliverCharlesworth hey, thanks for the reply. There is only the master branch, still not possible? I checked this post: https://stackoverflow.com/questions/454734/how-can-one-change-the-timestamp-of-an-old-commit-in-git# – Kejsi Struga Nov 12 '17 at 14:38
  • 1
    What matters is not the number of branches, but whether the one(s) you want to modify have already been pushed. – Oliver Charlesworth Nov 12 '17 at 14:39
  • @kejsiStruga So...have you pushed this branch already, or is this branch already publicly shared? – Tim Biegeleisen Nov 12 '17 at 14:41
  • @OliverCharlesworth yes I have pushed the commits – Kejsi Struga Nov 12 '17 at 14:43
  • Yes, you can rewrite a commit to a point and then force push your branch to the repository. Oliver's comment was getting at that if the branch in question is already public, then everyone else using the branch would certainly see that the history was rewritten, i.e. they would know that something is up. If you haven't yet pushed the branch, then from the perspective of other people, it doesn't even yet exist, so yes in theory you could change the branch history all you want and no one else would really know. – Tim Biegeleisen Nov 12 '17 at 14:43

1 Answers1

2

It is not possible to change the date of a commit in Git, not without massive hacking. However, it is possible to rewrite a new commit in place of an old commit. You might be able to rewrite a certain commit at a certain time. An interactive rebase and filter-branch are two ways that the history of a branch can be rewritten. But in both cases, it will be very visible that one or more commits have be rewritten, by you.

In general, you should avoid rewriting history if possible. This answer assumed that the branch in question has already been shared publicly, i.e. other users have seen your branch. If your branch was never pushed, then technically you can rewrite it all you want, and no one will be able to tell a rewritten commit from the original; they would just see a bunch of commits on the remote.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360