Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

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

Parent

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?)

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

1 comment thread

General comments (8 comments)
Post
+1
−3

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.

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

1 comment thread

General comments (7 comments)
General comments
Hyperlynx‭ wrote over 3 years ago · edited over 3 years ago

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.

meriton‭ wrote over 3 years 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.

Hyperlynx‭ wrote over 3 years ago · edited over 3 years 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‭ wrote over 3 years ago · edited over 3 years 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.

meriton‭ wrote over 3 years 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.

Hyperlynx‭ wrote over 3 years ago

There's more than one way of using git well. I'm very happy to hear that your way works for you, and that you're always able to check in intermediate commits that do not break the build and are also changes that are meaningful to the rest of the team. My question was whether this is possible, and if not then for what reason --amend and rebase fix or squash do not alter the date. At that point we're already altering history.

Olin Lathrop‭ wrote over 3 years ago

"At that point we're already altering history". Exactly. That's the real problem you need to fix.