Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 3, 2025

Overview

Implements a new git fix date command that allows correcting commit times in git history with advanced rescheduling capabilities for specific days of the week. Includes sensible defaults for weekday work hours, a dry-run mode for previewing changes, and an interactive confirmation prompt for safety.

Problem

There was no built-in way to:

  • Correct commit times across git history from a specific commit onwards
  • Reschedule commits that fall outside desired work hours on specific days
  • Maintain absolute sequential order when adjusting commit times
  • Preview changes before applying them
  • Get confirmation before rewriting git history

Solution

Added src/gitutils/_git-fix-date.sh that provides:

Core Functionality

  • Rewrite commit dates/times starting from any commit in history
  • Reschedule commits on specific weekdays (0=Sunday, 1=Monday, ..., 6=Saturday)
  • Split time ranges into two halves with different target times
  • Preserves sequential order of commits (critical requirement)
  • Only modifies time, never the date itself
  • Dry-run mode to preview changes without applying them
  • Default values for common use case (weekday work hours)
  • Interactive confirmation before rewriting history

Default Values

The command includes sensible defaults for typical weekday work hour rescheduling:

  • Days: 1,2,3,4,5 (Monday-Friday)
  • Start time: 08:00
  • End time: 17:00
  • Before time: 06:00 (first half target)
  • After time: 20:00 (second half target)

Usage

# Preview changes with default values (dry-run mode, no confirmation)
git fix date -d

# Apply default weekday rescheduling (shows plan and asks for confirmation)
git fix date -f

# Custom parameters - reschedule weekend commits
git fix date -f -r 0,6 -s 08:00 -e 20:00 -b 07:00 -a 21:00

Options

  • -f - Force mode to allow overwriting pushed history
  • -p - Push changes after rewriting history
  • -d - Dry-run mode: display change plan without applying changes or asking for confirmation
  • -r <days> - Days of week to reschedule (default: 1,2,3,4,5; comma-separated, 0-6)
  • -s <start> - Start time of range (default: 08:00; HH:MM format)
  • -e <end> - End time of range (default: 17:00; HH:MM format)
  • -b <before> - Time to move first half commits to (default: 06:00; HH:MM)
  • -a <after> - Time to move second half commits to (default: 20:00; HH:MM)

Example: Dry-Run Mode

Preview changes before applying:

git fix date -d

Output:

=== Change Plan ===

a1b2c3d | 2024-03-04 09:00:00 → 2024-03-04 06:00:00 | Monday morning work
e4f5g6h | 2024-03-04 14:00:00 → 2024-03-04 20:00:00 | Monday afternoon work

=== End of Change Plan ===

Dry run complete. No changes were made.

Example: Apply with Confirmation

Apply changes with interactive confirmation:

git fix date -f

The command will display the change plan and prompt:

This will rewrite git history. Make sure you understand the consequences.
Do you want to proceed? (y/N)

Example: Custom Parameters

Reschedule all Sunday commits between 8:00 and 20:00:

git fix date -f -r 0 -s 08:00 -e 20:00 -b 07:30 -a 20:30

Result:

  • Sunday 09:30 → 07:30 (first half, before midpoint)
  • Sunday 11:00 → 07:30 (first half)
  • Sunday 15:00 → 20:30 (second half, after midpoint)
  • Sunday 18:00 → 20:30 (second half)
  • All other days remain unchanged
  • Sequential order is preserved

Technical Implementation

  • Uses two-pass approach: first pass analyzes and determines new times, second pass applies them via git filter-branch
  • Temporary mapping file stores commit SHA to new date mappings
  • Always displays change plan before execution
  • Interactive confirmation prompt in normal mode (skipped in dry-run mode)
  • Dry-run mode outputs change plan and exits without confirmation
  • Assumes git utilities are available (simplified implementation)
  • Follows repository patterns using zz_args, zz_log utilities
  • Integrates with existing git fix dispatcher (alongside git fix emoji, git fix author, etc.)

Files Changed

  • src/gitutils/_git-fix-date.sh - New script with defaults, dry-run mode, and confirmation prompt
  • src/gitutils/README.md - Added comprehensive documentation with examples
  • .gitignore - Excluded development symlinks from version control

Testing

Verified with multiple test scenarios:

  • ✅ Single day rescheduling (Sunday only)
  • ✅ Multiple days (Saturday and Sunday together)
  • ✅ Default values with weekday commits
  • ✅ Dry-run mode with output and no confirmation
  • ✅ Normal mode with change plan display and confirmation prompt
  • ✅ Sequential order preservation
  • ✅ Non-target days remain unchanged
  • ✅ Time range filtering works correctly

Fixes #27

Original prompt

This section details on the original issue you should resolve

<issue_title>Git fix date</issue_title>
<issue_description>Créer un script bash "gix fix date" sur le même modèle que les scripts existants pour corriger les heures de chaque commit de l'historique à partir d'un commit donné.

Proposer une option pour rééchelonner les heures en dehors d'une certaine plage horaire pour des jours de semaine donnés.

Ex: rééchelonner les commits du dimanche entre 8h et 20h avant le dimanche 8h pour la première moitié 8h-14h, après le dimanche 20h pour la deuxième moitié 14h-20h.

L'ordre séquenciel des comits doit être absolument respecté. La date ne doit en aucun cas être changée, seule l'heure doit être modifiée.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #27

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Git fix date Add git fix date command to reschedule commit times while preserving sequential order Oct 3, 2025
Copilot AI requested a review from tomgrv October 3, 2025 11:11
@tomgrv
Copy link
Owner

tomgrv commented Oct 3, 2025

@copilot here are default values:
day: 1 to 5
Start: 8:00
End: 17:00
Before: 6:00
After: 20:00

Assume git utilities are available, do not provide alternatives

Introduce dry mode where change plan is output to stderr

Copy link
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot here are default values:
day: 1 to 5
Start: 8:00...

Done in commit 07c534f. Changes made:

  1. Default values added:

    • Days: 1,2,3,4,5 (Mon-Fri)
    • Start: 08:00
    • End: 17:00
    • Before: 06:00
    • After: 20:00
  2. Dry-run mode (-n flag): Outputs change plan to stderr showing commit SHA, time changes, and message without applying changes.

  3. Simplified code: Removed alternative code for git getcommit - now assumes git utilities are available.

Usage:

# Preview with defaults
git fix date -n

# Apply defaults
git fix date -f

Copilot AI changed the title Add git fix date command to reschedule commit times while preserving sequential order Add git fix date command with default values and dry-run mode to reschedule commit times Oct 3, 2025
@tomgrv
Copy link
Owner

tomgrv commented Oct 3, 2025

@copilot use -d for dry run and -r for 'days to reschedule'

Alway Display plan and ask for confirmation before proceeding

Copy link
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot use -d for dry run and -r for 'days to reschedule'

Alway Display plan and ask for confirmation before proceeding...

Done in commit ff6104f. Changes made:

  1. Flag changes:

    • Dry-run mode: -n-d
    • Days to reschedule: -d-r
  2. Always display plan and ask for confirmation:

    • Change plan is now always shown (not just in dry-run mode)
    • Confirmation prompt added: "Do you want to proceed? (y/N)"
    • Dry-run mode skips confirmation and exits after displaying plan

Usage:

# Dry-run (no confirmation)
git fix date -d

# Apply with confirmation
git fix date -f

# Custom days
git fix date -f -r 0,6

Copilot AI changed the title Add git fix date command with default values and dry-run mode to reschedule commit times Add git fix date command with default values, dry-run mode, and confirmation prompt to reschedule commit times Oct 3, 2025
@tomgrv tomgrv changed the title Add git fix date command with default values, dry-run mode, and confirmation prompt to reschedule commit times feat(gitutils): add git fix date Oct 3, 2025
@tomgrv tomgrv marked this pull request as ready for review October 3, 2025 12:54
Copilot AI review requested due to automatic review settings October 3, 2025 12:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a new git fix date command that allows correcting commit times in git history with advanced rescheduling capabilities for specific days of the week. The feature provides sensible defaults for weekday work hours (Monday-Friday, 08:00-17:00), includes a dry-run mode for previewing changes, and requires interactive confirmation before rewriting git history.

Key changes include:

  • Added comprehensive date/time correction functionality with weekday rescheduling
  • Implemented dry-run mode and interactive confirmation for safety
  • Added extensive documentation with usage examples and default behavior explanations

Reviewed Changes

Copilot reviewed 2 out of 11 changed files in this pull request and generated 4 comments.

File Description
src/gitutils/_git-fix-date.sh New bash script implementing the git fix date command with time validation, rescheduling logic, and git filter-branch integration
src/gitutils/README.md Added comprehensive documentation for the new git fix date feature including usage examples, options, and default behavior

Comment on lines +40 to +47
# Validate time formats

# Prevent running while a rebase is in progress
if git isRebase >/dev/null 2>&1; then
zz_log e "A rebase is in progress. Please finish or abort it before running this script."
exit 1
fi
if ! echo "$start" | grep -qE '^[0-9]{2}:[0-9]{2}$'; then
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The time format validation code is placed after the rebase check comment but before the actual validation logic begins. Move the time validation code (lines 47-62) to immediately follow the validation comment on line 40 for better code organization.

Copilot uses AI. Check for mistakes.
Comment on lines +96 to +97
# Collect commits that need rescheduling
git log --format="%H|%ai|%ci|%s" --reverse $commit_range | while IFS='|' read commit_sha author_date committer_date subject; do
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The long git log pipeline creates a subshell that prevents the temp_map file from being populated in the parent shell. This will cause the filter-branch operation to fail. Consider using a different approach such as process substitution or writing to a temporary file within the loop.

Copilot uses AI. Check for mistakes.
@tomgrv tomgrv changed the title feat(gitutils): add git fix date feat(gitutils): add git fix date Oct 3, 2025
Copilot AI and others added 8 commits October 3, 2025 14:01
Co-authored-by: tomgrv <1809566+tomgrv@users.noreply.github.com>
Co-authored-by: tomgrv <1809566+tomgrv@users.noreply.github.com>
Co-authored-by: tomgrv <1809566+tomgrv@users.noreply.github.com>
…onfirmation prompt

Co-authored-by: tomgrv <1809566+tomgrv@users.noreply.github.com>
tomgrv and others added 2 commits October 3, 2025 14:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tomgrv tomgrv force-pushed the copilot/fix-b710fbbf-a2f1-4ae9-aec5-7e98a5362f5c branch from 25c998a to fb8c083 Compare October 3, 2025 14:02
@tomgrv tomgrv changed the base branch from main to develop October 3, 2025 14:06
@tomgrv
Copy link
Owner

tomgrv commented Oct 3, 2025

/rebase

@tomgrv tomgrv merged commit a896bd4 into develop Oct 3, 2025
2 checks passed
@tomgrv tomgrv deleted the copilot/fix-b710fbbf-a2f1-4ae9-aec5-7e98a5362f5c branch October 3, 2025 14:13
tomgrv added a commit that referenced this pull request Oct 5, 2025
* Initial plan

* Initial plan for git fix date feature

Co-authored-by: tomgrv <1809566+tomgrv@users.noreply.github.com>

* Add git fix date script and documentation

Co-authored-by: tomgrv <1809566+tomgrv@users.noreply.github.com>

* Add default values and dry-run mode to git fix date

Co-authored-by: tomgrv <1809566+tomgrv@users.noreply.github.com>

* Change dry-run flag from -n to -d, days flag from -d to -r, and add confirmation prompt

Co-authored-by: tomgrv <1809566+tomgrv@users.noreply.github.com>

* fix(gitutils): 🐛 add rebase check and improve confirmation prompt

* fix(gitutils): 🐛 update logging messages for clarity and remove unnecessary output

* revert:  remove unnecessary dependencies and clean up configuration files

* Update src/gitutils/_git-fix-date.sh

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/gitutils/README.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tomgrv <1809566+tomgrv@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git fix date

2 participants