Function: magit-reshelve-since

magit-reshelve-since is an autoloaded, interactive and byte-compiled function defined in magit-extras.el.

Signature

(magit-reshelve-since COMMIT KEYID)

Documentation

Change the author and committer dates of the commits since COMMIT.

Ask the user for the first reachable commit whose dates should be changed. Then read the new date for that commit. The initial minibuffer input and the previous history element offer good values. The next commit will be created one minute later and so on.

This command is only intended for interactive use and should only be used on highly rearranged and unpublished history.

If KEYID is non-nil, then use that to sign all reshelved commits. Interactively use the value of the "--gpg-sign" option in the list returned by magit-rebase-arguments.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-extras.el
;;;###autoload
(defun magit-reshelve-since (commit keyid)
  "Change the author and committer dates of the commits since COMMIT.

Ask the user for the first reachable commit whose dates should
be changed.  Then read the new date for that commit.  The initial
minibuffer input and the previous history element offer good
values.  The next commit will be created one minute later and so
on.

This command is only intended for interactive use and should only
be used on highly rearranged and unpublished history.

If KEYID is non-nil, then use that to sign all reshelved commits.
Interactively use the value of the \"--gpg-sign\" option in the
list returned by `magit-rebase-arguments'."
  (interactive (list nil
                     (transient-arg-value "--gpg-sign="
                                          (magit-rebase-arguments))))
  (let* ((current (or (magit-get-current-branch)
                      (user-error "Refusing to reshelve detached head")))
         (backup (concat "refs/original/refs/heads/" current)))
    (cond
      ((not commit)
       (when (and (magit-ref-p backup)
                  (not (magit-y-or-n-p
                        (format "Backup ref %s already exists.  Override? "
                                backup))))
         (user-error "Abort"))
       (magit-log-select
         (lambda (rev)
           (magit-reshelve-since rev keyid))
         "Type %p on a commit to reshelve it and the commits above it,"))
      (t
       (cl-flet ((adjust (time offset)
                   (format-time-string
                    "%F %T %z"
                    (+ (floor time)
                       (* offset 60)
                       (- (car (decode-time time)))))))
         (let* ((start (concat commit "^"))
                (range (concat start ".." current))
                (time-rev (adjust (float-time (string-to-number
                                               (magit-rev-format "%at" start)))
                                  1))
                (time-now (adjust (float-time)
                                  (- (string-to-number
                                      (magit-git-string "rev-list" "--count"
                                                        range))))))
           (push time-rev magit--reshelve-history)
           (let ((date (floor
                        (float-time
                         (date-to-time
                          (read-string "Date for first commit: "
                                       time-now 'magit--reshelve-history))))))
             (with-environment-variables (("FILTER_BRANCH_SQUELCH_WARNING" "1"))
               (magit-with-toplevel
                 (magit-run-git-async
                  "filter-branch" "--force" "--env-filter"
                  (format
                   "case $GIT_COMMIT in %s\nesac"
                   (mapconcat
                    (lambda (rev)
                      (prog1
                          (concat
                           (format "%s) " rev)
                           (and (not magit-reshelve-since-committer-only)
                                (format "export GIT_AUTHOR_DATE=\"%s\"; " date))
                           (format "export GIT_COMMITTER_DATE=\"%s\";;" date))
                        (cl-incf date 60)))
                    (magit-git-lines "rev-list" "--reverse" range)
                    " "))
                  (and keyid
                       (list "--commit-filter"
                             (format "git commit-tree --gpg-sign=%s \"$@\";"
                                     keyid)))
                  range "--"))
               (set-process-sentinel
                magit-this-process
                (lambda (process event)
                  (when (memq (process-status process) '(exit signal))
                    (if (> (process-exit-status process) 0)
                        (magit-process-sentinel process event)
                      (process-put process 'inhibit-refresh t)
                      (magit-process-sentinel process event)
                      (magit-run-git "update-ref" "-d" backup)))))))))))))