Notifications
Mark all as read
Q&A

How can I make --reset-author the default?

+4
−3

I do a lot of rebasing and amending of my topic branches. I don't think it's especially useful for me or my colleagues to see in the logs what date it was when I first started working on the particular topic - only when I actually submitted it.

I know I can explicitly reset the date of my commit to the current time using git commit --amend --reset-author. But is there any way I can change that behaviour to be the default when I rebase or amend, so I don't have to type it every time?

For example: on Monday I put in a new feature and submit the patch for peer review. On Tuesday, my team lead wants me to make some changes to my patch and resubmit. On Wednesday I make the changes, git commit --amend them, and submit the new patch for review. On Thursday the new changes are approved. I pull the master branch and rebase my changes on it.

Right now, that commit entry in my log will still be timestamped Monday, even though I amended on Wednesday and rebased on Thursday. In the future, when we look through the logs, the useful date is when I've finished and push the change (Thursday), not the date of the first commit that no longer exists (Monday). To update the date, now on Thursday, I need to go a git commit --amend --reset-author --no-edit. If I don't do that, it will still say that my change was on a Monday, when it was not.

(Alternatively: am I missing something here? Is it actually useful for people to know that I started work on the topic on Monday, rather than that the change was actually put in on Thursday? Is there a way to see both the datestamp of a commit and the date the commit was actually added to the tree?)

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

8 comments

what kind of functionality do you want? do you need the date to be constant? Razetime‭ 18 days ago

Alternatively, the info is there and I don't believe it's getting in the way of anyone, so why bother removing it? Moshi‭ 18 days ago

@Moshi where is that info? Hyperlynx‭ 17 days ago

@Hyperlynx I'm not sure what you're asking - you asked how to remove that info right? Moshi‭ 17 days ago

@Moshi I'm not trying to remove the date, I'm trying to reset it to the current date. That's what --reset-author does. I want that behaviour by default, when I do a commit --amend or a squash. I mistakenly thought --date= also did that, when in fact it doesn't work at all. Hyperlynx‭ 14 days ago

Show 3 more comments

3 answers

+5
−0

You should be able to alias the string to something short. For example, I have

git config --global alias.a  'add .'
git config --global alias.ci commit

and so instead of

git add .
git commit -m'Message'

I can do

git a
git ci -m'Message'

In your case, it would be

git config --global alias.ci 'commit --amend --reset-author'

if I am understanding the question correctly.

Why does this post require moderator attention?
You might want to add some details to your flag.

2 comments

This is really the way to go, IMHO. Just alias the command and done. This is also done in the oh-my-zsh project for zsh itself, with gc = git commit, gst = git status, and so on. ghost-in-the-zsh‭ 12 days ago

Perfect! I didn't even know git had its own alias system, either. It doesn't deal with interactive rebasing, but I can insert it into the rebase TODO. Hyperlynx‭ 12 days ago

+1
−2

Rather that doing git commit --amend --date= every time you commit, you can coalesce commits at merge time using git merge --squash.

That said, for non-trivial topic branches, it is usually valuable to retain the commits in the topic branch to figure out why a particular change was made. For instance, if you are developing a feature in a feature branch, this might require some refactorings, or non-obvious bugfixes, that would be better described in a commit of their own.

In general, I find a detailed and truthful history more valuable than a pretty one: The purpose of history is not to look beautiful, but to be able to figure out why a certain change was made. Yes, unnecessary information may slow the inspection of history, but deleted necessary information will halt it.

PS: You may have noticed that this answer does not mention commit dates. That's because they rarely matter in my experience: When inspecting history, I care about the "what" and "why", not usually the "when". And even when I care about the "when", it'll only be about the year, or the release, not the day. Therefore, the choice of commit frequency or squashing should not be affected by dating considerations.

Why does this post require moderator attention?
You might want to add some details to your flag.

7 comments

Nobody wants or needs to see "nearly done I think", "no, the menu bar still flickers, try call FooBar::blah instead", "TESTING ONLY: printfs", "GOT IT it was a problem in Baz.dll" "Reverted: TESTING ONLY: printfs" in the log. The only commit message that is relevant or necessary, for the purposes of communicating with the rest of the team is "Implemented new WidgetWodget screen (JIRA-932)". This is the "checkpoint commits" workflow. Hyperlynx‭ 17 days ago

Sorry to hear your team writes such abysmal commit messages. Concluding from this that commit messages can not be useful would would be a mistake though. meriton‭ 14 days ago

You've completely missed my point. Nobody in my team pushes commits like that. The way I (and presumably my colleagues) work is to make a topic branch, let's say for ticket 932. I then commit whenever I need to save my progress, eg because I'm about to try a new approach and don't want to lose my work. Finally, when I'm finished 932, I interactive rebase my topic branch to squash it down, and write a commit message that's going to help my team. See https://sandofsky.com/workflow/git-workflow/ Hyperlynx‭ 14 days ago

The issue here is that squashing and amending uses the timestamp of the original commit, not what you're squashing into it. The rest is irrelevant to the topic at hand. Hyperlynx‭ 14 days ago

You did ask whether you are missing something. Yes, you are: If you use git well, you will be writing meaningful intermediary commits, so amending or squashing will be a rare event, so there is no need to "fix" commit dates. I am somewhat puzzled that you would ask whether you are missing something, but not want to hear what it is. And by the way, git merge --squash uses the current date, not the date of the commits being squashed. meriton‭ 13 days ago

Show 2 more comments
+1
−3

Here's the problem:

Wednesday I make the changes, git commit --amend them

Just do a normal commit. You are trying to re-write, or cover up, history. That's generally bad.

The record should reflect what really happened: You submitted a patch, it was rejected for xxx reason, you changed the patch, it was accepted. You have no way of knowing what part of that might be useful information a month, a year, or years in the future. The cost is tiny. Do it right.

I haven't altered anything that has been pushed

Actually you are. You are changing the comments for the commit.

It seems the overall problem is that your group uses commit comments poorly, and therefore values them less.

I should be able to read all the drafts, right down to the first one, rather than just the final printed edition

Yes. That's rather the basis of source control. Remember also that this is for the people the write the software, not the public that just uses the software.

Why does this post require moderator attention?
You might want to add some details to your flag.

4 comments

I have no power to change our workflow. Furthermore, I'm not changing history, I haven't altered anything that has been pushed. I'm changing the commits that I'm authoring, before pushing them to the shared repo. This isn't Subversion, where Every Revision Is Sacred. What you're saying is like saying that when I go buy a book I should be able to read all the drafts, right down to the first one, rather than just the final printed edition. https://sandofsky.com/workflow/git-workflow/ Hyperlynx‭ 13 days ago

It makes it hard to follow the thread of conversation if you're going to reply by editing your answer, rather than not here. You have misunderstood, or I have expressed myself poorly. I am editing commits which have not been pushed. That's a statement of fact! I am working on a local branch, editing and rebasing to produce a history that is accurate and useful for my team, and only once it passes review is it actually pushed. Hyperlynx‭ 12 days ago

As for your value judgement about how we use Git, that's absolutely just your opinion. I could say the same for how you evidently use Git, since you're apparently using it like it's SVN and not getting the full benefit of the tool you have. Read the link I posted. Or don't, since this is irrelevant to what I actually asked anyway. Hyperlynx‭ 12 days ago

Besides which, if your attitude is "editing commits is altering history, which is always wrong and is forbidden" then Git probably isn't the tool for you. Hyperlynx‭ 12 days ago

Sign up to answer this question »