Imagine that you made some commits for which you would like to update the time or a date.(so that you would keep only the chronological order)
Now if you were to do it on the latest commit, you can just run:
GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)"
and that would update the date of the last commit, so you can then push
or push force
it.
Multiple commits
To perform this action in bulk mode you can just run:
git rebase HEAD~{number of commits} --ignore-date
You can also create a shortcut in your ~/.gitconfig
like so:
[alias]
refresh = "!f() { git rebase HEAD~$1 --ignore-date; }; f"
where the parameter would be number of commits starting from HEAD
to update, i.e.:
git refresh 6
Top comments (8)
Could I get more reason why I'd want to rewrite chronological order?
You don’t rewrite the chronological order. You rewrite timestamps but you keep the chronological order.
And why would I want to do that?
Probably to keep GitHub activity streak or something. Those sweet internet points 🙂
Chronological is in the order in which events happened (it is in relation to time). The original time stamp is the chronological order.
Why would I want to change the time stamp?
Like you said, the chronological order is an order of events relative to timescale, so if you change the initial time stamp, but the order stays the same but relative to a new timestamp, it doesn’t mean that you’ve changed the chronological order, you just switched the initial timestamp. The order is the same.
That being said, if you decided to take a sample of commits before recent commit/commits, and switched initial timestamp of the first commit of that sample so it comes after every commit, you would effectively change the chronological order, that is to say the sample would chronologically be after the latest commit/commits
Regarding the question «why?», I see several use cases, but my main intent of this exercise was to try to find a way to make part of your work seem to have been done at a later time then it was done initially, for instance if you sketched some code in the morning and wanted to be able to push it as if it was done in the evening.
OK, I guess I was thinking about reordered Commits can happen.
Still not sure why the morning Commits would be desired to be changed for the evening.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.