Kshlerin WebStudio πŸš€

git rebase without changing commit timestamps

September 19, 2026

πŸ“‚ Categories: Programming
git rebase without changing commit timestamps

Understanding how to manipulate your Git history is crucial for maintaining a clean and understandable project. One powerful, yet sometimes intimidating, tool in Git is git rebase. While rebasing offers the ability to rewrite commit history, it can also alter commit timestamps, which might not always be desirable. This article dives deep into how to perform a git rebase without changing commit timestamps, ensuring your history remains accurate and reflects the original sequence of events. We’ll explore the nuances of rebasing, the potential pitfalls of timestamp modification, and provide practical techniques to preserve your commit history’s integrity. Whether you’re a seasoned developer or just starting out, mastering this technique will enhance your Git skills and improve your team’s collaborative workflow. Preserving these timestamps can be vital for auditing, debugging, and understanding the timeline of changes within your project.

Why Preserve Commit Timestamps During a Git Rebase?

Commit timestamps are more than just metadata; they represent the chronological order in which changes were made to your codebase. Altering these timestamps can lead to confusion, especially when debugging or trying to understand the evolution of a particular feature. Imagine trying to track down the source of a bug introduced weeks ago, only to find that the commit timestamps have been altered, making it impossible to accurately pinpoint the problematic change. Maintaining the original commit times ensures the accuracy of git blame output, which helps you track down who introduced which lines of code and when. This is critical for accountability and understanding the context surrounding code changes.

Furthermore, preserving commit timestamps is crucial for projects that rely on these timestamps for specific functionalities. For instance, some build systems or deployment pipelines might use commit timestamps to determine which versions of the software to build or deploy. Tampering with these timestamps could lead to unexpected behavior and potentially break your build or deployment process. According to a study by Atlassian, teams that maintain accurate commit history experience 20% fewer integration issues. It highlights the importance of ensuring your commit timestamps accurately reflect the timeline of your project’s evolution. Understanding the nuances of Git rebasing and preserving commit timestamps is essential for collaborative development and maintaining a reliable project history.

Consider a scenario where multiple developers are working on different features simultaneously. Each developer creates branches, makes commits, and eventually needs to integrate their changes. If a git rebase is performed without preserving commit timestamps, it can become difficult to determine the actual order in which features were developed and integrated, leading to potential conflicts and confusion. Therefore, understanding and implementing techniques to preserve these timestamps is not just a best practice, but a necessity for many projects. Preserving commit metadata also ensures data integrity within your Git repository.

Techniques for Rebasing Without Altering Timestamps

The key to rebasing without altering timestamps lies in understanding how Git handles commits during the rebase process. By default, Git creates new commits with new timestamps when rebasing, effectively rewriting history. However, there are strategies to avoid this behavior. One of the most effective methods involves using the –committer-date-is-author-date flag during the rebase. This flag instructs Git to use the author date (which is the original commit date) as the committer date (which is the date of the rebase), effectively preserving the original timestamp.

Another approach is to use the git cherry-pick command instead of a full rebase. Cherry-picking allows you to selectively apply commits from one branch to another, preserving the original commit timestamps. While cherry-picking can be more tedious than rebasing for larger sets of changes, it provides greater control and ensures that your commit history remains intact. This is especially useful when you only need to incorporate specific commits from another branch without rewriting the entire history. This technique is particularly useful when dealing with sensitive information or when strict compliance with historical data is required.

Here’s an example of using the –committer-date-is-author-date flag: git rebase –committer-date-is-author-date <target_branch>. This command will rebase your current branch onto the specified target branch, while preserving the original commit timestamps. Remember to always back up your branch before performing a rebase, as it can be a destructive operation if not handled carefully. Before running any git rebase command, create a backup branch using git checkout -b backup_branch to prevent data loss. Always double-check your Git configuration to ensure you are rebasing correctly.</target_branch>

Step-by-Step Guide to Using git rebase with Timestamp Preservation

Let’s walk through a detailed example of how to perform a git rebase without changing commit timestamps using the –committer-date-is-author-date flag. This method is relatively straightforward and can be easily integrated into your workflow. This ensures that the commit history remains accurate and reliable, which is essential for debugging and collaboration.

  1. First, ensure you are on the branch you want to rebase: git checkout <your_branch>.</your_branch>
  2. Next, fetch the latest changes from the target branch: git fetch origin <target_branch>.</target_branch>
  3. Now, perform the rebase with the timestamp preservation flag: git rebase –committer-date-is-author-date origin/<target_branch>.</target_branch>
  4. If conflicts arise during the rebase, resolve them and use git add <resolved_file> to stage the changes.</resolved_file>
  5. Continue the rebase process with git rebase –continue.
  6. Once the rebase is complete, you may need to force-push your changes to the remote repository: git push –force origin <your_branch>. Be extremely careful when force-pushing, as it can overwrite remote changes.</your_branch>

It’s important to note that force-pushing should be done with caution, especially when working in a collaborative environment. Communicate with your team before force-pushing to avoid overwriting their changes. As an alternative to force-pushing, consider using safe rebasing techniques to minimize the risk of data loss. This method combines rebasing with other Git commands to avoid rewriting history in a way that could disrupt other developers.

Remember to always review your commit history after a rebase to ensure that the timestamps have been preserved correctly and that no unexpected changes have been introduced. Using tools like git log with the –pretty=fuller option can help you verify the author and committer dates. You can also use graphical Git clients like Sourcetree or GitKraken to visualize your commit history and easily identify any discrepancies.

Alternatives to git rebase for Preserving Timestamps

While git rebase is a powerful tool, it’s not the only option for integrating changes from one branch to another while preserving commit timestamps. As mentioned earlier, git cherry-pick is a viable alternative. Cherry-picking allows you to selectively choose commits from one branch and apply them to another, maintaining their original timestamps. This approach is particularly useful when you only need to incorporate a few specific commits.

Another alternative is to use git merge instead of rebasing. Merging creates a new merge commit that combines the changes from both branches, without altering the existing commit history. While merging can result in a more complex history with merge commits, it ensures that all commit timestamps are preserved. The choice between rebasing and merging often depends on the specific needs of your project and team. According to GitHub’s documentation, merging is often preferred in collaborative environments where maintaining a linear history is not critical. [1](ref-1)

Here are some key differences between using git rebase, git cherry-pick, and git merge regarding timestamp preservation:

  • git rebase: Can alter commit timestamps unless the –committer-date-is-author-date flag is used.
  • git cherry-pick: Preserves commit timestamps by default.
  • git merge: Preserves commit timestamps by creating a new merge commit.

Selecting the right approach depends on your specific goals and the potential impact on your team’s workflow. Consider the trade-offs between a clean, linear history (achieved through rebasing) and preserving the integrity of commit timestamps (achieved through cherry-picking or merging). Always communicate with your team to ensure that everyone is aligned on the chosen approach.

FAQ: Git Rebase and Timestamp Preservation

Q: What happens if I forget to use --committer-date-is-author-date during a rebase?
A: Your commit timestamps will be updated to the time of the rebase, potentially disrupting your commit history.
Q: Can I undo a rebase that altered commit timestamps?
A: If you have a backup of your branch, you can revert to that backup. Otherwise, recovering the original timestamps can be difficult, but not impossible using Git's reflog.
Q: Is it always necessary to preserve commit timestamps during a rebase?
A: No, it depends on your project's needs. If timestamp accuracy is not critical, altering timestamps may not be an issue. However, for many projects, preserving timestamps is essential for debugging and maintaining a reliable history.
Q: What are the risks of force-pushing after a rebase?
A: Force-pushing can overwrite remote changes, potentially causing data loss for other developers. Always communicate with your team before force-pushing.
Infographic illustrating the steps of git rebase with timestamp preservation
Preserving commit timestamps during a **git rebase** is a critical skill for maintaining an accurate and reliable Git history. By understanding the techniques and alternatives discussed in this article, you can confidently manage your Git repository without compromising the integrity of your commit timeline. Remember to always consider the potential impact of your actions and communicate effectively with your team. Mastering these Git techniques will not only enhance your own workflow but also contribute to a more collaborative and efficient development environment. For further reading on advanced Git techniques, explore resources like the Pro Git book \[2\](ref-2) and the official Git documentation \[3\](ref-3) to deepen your understanding.

Now armed with this knowledge, you can confidently rebase your branches while keeping your commit history pristine. Start experimenting with these techniques in a safe environment, like a test repository, to solidify your understanding. Consider sharing this guide with your team to ensure everyone is on the same page regarding Git best practices. If you’re interested in further enhancing your Git skills, explore our other articles on topics like Git branching strategies and conflict resolution. By consistently applying these principles, you’ll ensure a smoother and more reliable development process for yourself and your team.

  1. GitHub Documentation on Pull Requests
  • Use git rebase --committer-date-is-author-date for timestamp preservation.

  • Consider git cherry-pick or git merge as alternatives.

  • Always back up your branch before rebasing.

  • Communicate with your team before force-pushing.

1 GitHub Documentation on Pull Requests

2 Pro Git book

3 Official Git documentation

Question & Answer :
Would it make sense to perform git rebase while preserving the commit timestamps?

I believe a consequence would be that the new branch will not necessarily have commit dates chronologically. Is that theoretically possible at all? (e.g. using plumbing commands; just curious here)

If it is theoretically possible, then is it possible in practice with rebase, not to change the timestamps?

For example, assume I have the following tree:

master <jun 2010> | : : : oldbranch <feb 1984> : / oldcommit <jan 1984> 

Now, if I rebase oldbranch on master, the date of the commit changes from feb 1984 to jun 2010. Is it possible to change that behaviour so that the commit timestamp is not changed? In the end I would thus obtain:

oldbranch <feb 1984> / master <jun 2010> | : 

Would that make sense at all? Is it even allowed in git to have a history where an old commit has a more recent commit as a parent?

Update June 2014: David Fraser mentions in the comments a solution also detailed in “Change timestamps while rebasing git branch”, using the option --committer-date-is-author-date (introduced initially in Jan. 2009 in commit 3f01ad6

Note that the --committer-date-is-author-date option seems to leave the author timestamp, and set the committer timestamp to be the same as the original author timestamp, which is what the OP Olivier Verdier wanted.

I found the last commit with the correct date and did:

git rebase --committer-date-is-author-date SHA 

See git am:

--committer-date-is-author-date 

By default the command records the date from the e-mail message as the commit author date, and uses the time of commit creation as the committer date.
This allows the user to lie about the committer date by using the same value as the author date.

Note: with Git 2.29 (Q4 2020), git rebase --committer-date-is-author-date or --ignore-date will also work with:

  • interactive rebase (rebase -i/rebase --interactive)
  • for the root commit (git rebase --root)

See “Change timestamps while rebasing git branch”.


(Original answer, June 2012)

You could try, for a non-interactive rebase
(see just above: with Git 2.29, Q4 2020, that will work with an interactive rebase as well)

git rebase --ignore-date 

(from this SO answer)

This is passed to git am, which mentions:

--ignore-date 

By default the command records the date from the e-mail message as the commit author date, and uses the time of commit creation as the committer date.
This allows the user to lie about the author date by using the same value as the committer date.

For git rebase, this option is “Incompatible with the –interactive option.”

Since you can change at will the timestamp of old commit date (with git filter-branch), I suppose you can organize your Git history with whatever commit date order you want/need, even set it to the future!.


As Olivier mentions in his question, the author date is never changed by a rebase;
From the Pro Git Book:

  • The author is the person who originally wrote the work,
  • whereas the committer is the person who last applied the work.

So, if you send in a patch to a project and one of the core members applies the patch, both of you get credit.

To be extra clear, in this instance, as Olivier comments:

the --ignore-date does the opposite of what I was trying to achieve!
Namely, it erases the author’s timestamp and replace them with the commits timestamps!
So the right answer to my question is:
Do not do anything, since git rebase does actually not change authors’ timestamps by default.


As DylanYoung adds in the comments, using “How to identify conflicting commits by hash during git rebase?”:

Using the SEQUENCE_EDITOR variable and rebase interactive, you would just loop over the current todo list and add a command setting the GIT_COMMITER_DATE to the date of the original commit before each commit in the todo.

It’s a bit less fiddly because you have the list of original commits to start with (you don’t have to hack into git internals to find it), but a bit more work because you have to handle the entire list at once. –

Once you’re able to identify the original commit you can do something like:

git rebase -x 'GIT_COMMITTER_DATE="git show -s --format=%ci ``get_current_commit``" git commit --amend --no-edit