Giter Club home page Giter Club logo

git-undo-el's Introduction

git-undo

When M-x git-undo is called on a region, it will first:

  1. Replace the region, if it has been modified but not saved, with the current working tree version.

  2. Replace the region, if it has been modified and saved, with the current HEAD version.

  3. Successively walk back through all the versions of that region found in the Git history.

Note that if this command is run twice, it begins the walkthrough over again, since there's no easy way of knowing at which point in history you were before you repeated the command. Perhaps this could be added by searching through the Git history for matching contents.

Example use

Mark a region in a Git-controlled buffer and execute M-x git-undo. Then use C-x z to step through changes to that region in Git's history.

git-undo-el's People

Contributors

jwiegley avatar leungbk avatar tarsius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

git-undo-el's Issues

MELPA?

Hi,

this not an issue, I am just curious: is there any plan to add this package to MELPA (or ELPA)?

Thank you :)

Not work on emacs 28.2 ?

Following is error log when run git-undo on a selected region.


Debugger entered--Lisp error: (search-failed "^@@")
re-search-forward("^@@")
(progn (shell-command (format "git --no-pager diff -U%d HEAD -- %s" buffer-lines (file-name-nondirectory file-name)) (current-buffer)) (goto-char (point-min)) (re-search-forward "^@@") (forward-line) (let ((adjustment 0) (line 1) adjusted-start adjusted-end) (while (not (eobp)) (let* ((val (char-after))) (cond ((eql val 43) (let nil (setq adjustment ...))) ((eql val 45) (let nil (setq adjustment ...))) (t (let nil (setq line ...))))) (if (= (- start adjustment) line) (progn (setq adjusted-start (+ start adjustment)))) (if (= (- end adjustment) line) (progn (setq adjusted-end (+ end adjustment)) (goto-char (point-max)))) (forward-line)) (cons (1+ adjusted-start) adjusted-end)))
(unwind-protect (progn (shell-command (format "git --no-pager diff -U%d HEAD -- %s" buffer-lines (file-name-nondirectory file-name)) (current-buffer)) (goto-char (point-min)) (re-search-forward "^@@") (forward-line) (let ((adjustment 0) (line 1) adjusted-start adjusted-end) (while (not (eobp)) (let* ((val (char-after))) (cond ((eql val 43) (let nil ...)) ((eql val 45) (let nil ...)) (t (let nil ...)))) (if (= (- start adjustment) line) (progn (setq adjusted-start (+ start adjustment)))) (if (= (- end adjustment) line) (progn (setq adjusted-end (+ end adjustment)) (goto-char (point-max)))) (forward-line)) (cons (1+ adjusted-start) adjusted-end))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
(save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (shell-command (format "git --no-pager diff -U%d HEAD -- %s" buffer-lines (file-name-nondirectory file-name)) (current-buffer)) (goto-char (point-min)) (re-search-forward "^@@") (forward-line) (let ((adjustment 0) (line 1) adjusted-start adjusted-end) (while (not (eobp)) (let* ((val ...)) (cond (... ...) (... ...) (t ...))) (if (= (- start adjustment) line) (progn (setq adjusted-start ...))) (if (= (- end adjustment) line) (progn (setq adjusted-end ...) (goto-char ...))) (forward-line)) (cons (1+ adjusted-start) adjusted-end))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))
(let ((temp-buffer (generate-new-buffer " temp" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (shell-command (format "git --no-pager diff -U%d HEAD -- %s" buffer-lines (file-name-nondirectory file-name)) (current-buffer)) (goto-char (point-min)) (re-search-forward "^@@") (forward-line) (let ((adjustment 0) (line 1) adjusted-start adjusted-end) (while (not (eobp)) (let* (...) (cond ... ... ...)) (if (= ... line) (progn ...)) (if (= ... line) (progn ... ...)) (forward-line)) (cons (1+ adjusted-start) adjusted-end))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
(let ((file-name (buffer-file-name)) (buffer-lines (line-number-at-pos (point-max)))) (let ((temp-buffer (generate-new-buffer " temp" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (shell-command (format "git --no-pager diff -U%d HEAD -- %s" buffer-lines (file-name-nondirectory file-name)) (current-buffer)) (goto-char (point-min)) (re-search-forward "^@@") (forward-line) (let ((adjustment 0) (line 1) adjusted-start adjusted-end) (while (not ...) (let* ... ...) (if ... ...) (if ... ...) (forward-line)) (cons (1+ adjusted-start) adjusted-end))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))))
git-undo--compute-offsets(6 5)
(let* ((end-line (git-undo--compute-offsets (line-number-at-pos start) (1- (line-number-at-pos end)))) (start-line (if end-line (car-safe (prog1 end-line (setq end-line (cdr end-line)))) (signal 'wrong-number-of-arguments (list '(start-line . end-line) (length end-line)))))) (let ((temp-buffer (generate-new-buffer " temp" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (message "Retrieving Git history for lines %d to %d..." start-line end-line) (shell-command (format "git --no-pager log --no-expand-tabs -p -L%d,%d:%s" start-line end-line (file-name-nondirectory file-name)) (current-buffer)) (message "") (goto-char (point-min)) (let ((commit t) history) (while (and commit ... ...) (delete-region ... ...) (setq commit ...) (setq history ...)) (nreverse history))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))))
(let ((file-name (buffer-file-name))) (let* ((end-line (git-undo--compute-offsets (line-number-at-pos start) (1- (line-number-at-pos end)))) (start-line (if end-line (car-safe (prog1 end-line (setq end-line ...))) (signal 'wrong-number-of-arguments (list '... (length end-line)))))) (let ((temp-buffer (generate-new-buffer " temp" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (message "Retrieving Git history for lines %d to %d..." start-line end-line) (shell-command (format "git --no-pager log --no-expand-tabs -p -L%d,%d:%s" start-line end-line ...) (current-buffer)) (message "") (goto-char (point-min)) (let (... history) (while ... ... ... ...) (nreverse history))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))))
git-undo--build-history(134 162)
(set (make-local-variable 'git-undo--history) (git-undo--build-history start end))
(if (eq last-command 'git-undo) (git-undo--replace-region) (set (make-local-variable 'git-undo--region-start) (copy-marker start nil)) (set (make-local-variable 'git-undo--region-end) (copy-marker end t)) (set (make-local-variable 'git-undo--history) (git-undo--build-history start end)) (git-undo--replace-region))
git-undo(134 162)
funcall-interactively(git-undo 134 162)
command-execute(git-undo record)
execute-extended-command(nil "git-undo" "git-undo")
funcall-interactively(execute-extended-command nil "git-undo" "git-undo")
command-execute(execute-extended-command)


thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.